我有一個asp.net web應用程序,但未啓用ssl,並在啓用ssl的sharepoint 2010站點上使用lists.asmx。我已將lists.asmx添加爲名爲「myref」的Web引用。GetListItems「請求失敗,HTTP狀態401:未授權」
我正在使用的代碼如下:
Web.config文件片斷
<system.web>
<identity impersonate="true"/>
<authentication mode="Windows"/>
..........
</system.web>
ASPX代碼
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.xml" %>
<%@ Import Namespace="myref" %>
<%
Dim xmlDoc As XmlDocument = New System.Xml.XmlDocument()
Dim myQuery As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Query","")
myQuery.InnerXml = "<Where><Eq><FieldRef Name='_ModerationStatus' /><Value Type='ModStat'>2</Value></Eq></Where>"
Dim myViewFields As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields","")
myViewFields.InnerXml ="<FieldRef Name='_Status' /><FieldRef Name='owshiddenversion' />"
Dim myQueryOptions as XmlNode= xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions","")
myQueryOptions.InnerXml = "<Folder>my list</Folder>"
Dim mylist As new myref.Lists()
mylist.UseDefaultCredentials = true
mylist.PreAuthenticate = True
Dim ndLists As XmlNode = mylist.GetListItems("my list","",myQuery,myViewFields,100,myQueryOptions,"")
Response.Write(ndLists.outerxml)
%>
如果我使用上面的我得到錯誤:
Line 514: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetListItems", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 515: public System.Xml.XmlNode GetListItems(string listName, string viewName, System.Xml.XmlNode query, System.Xml.XmlNode viewFields, string rowLimit, System.Xml.XmlNode queryOptions, string webID) {
Line 516: object[] results = this.Invoke("GetListItems", new object[] {
Line 517: listName,
Line 518: viewName,
,如果我使用:的
Dim cache As CredentialCache = New CredentialCache()
cache.Add(New Uri(mylist.Url), "Negotiate", New NetworkCredential("userid", "password", "domain"))
代替
mylist.UseDefaultCredentials = true
它工作正常。 問題是我想通過登錄訪問asp.net網站的用戶的詳細信息,而不是硬編碼的用戶ID。
雖然在我的本地機器上無法在瀏覽器上工作的相同代碼可以正常工作,但如果我直接登錄到asp.net站點服務器並通過localhost/sitename/pagename.aspx直接訪問,情況會變得複雜。
檢查Web服務器上的應用程序事件日誌顯示了以下額外的信息,該網頁不顯示:
Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False
這對我來說似乎表明,它試圖用網絡服務連接到Web服務,而不是登錄的用戶詳細信息,除非您直接登錄到服務器。
- 的asp.net應用程序有Windows身份驗證的(非匿名)是必需的
- windows身份驗證傳遞到SharePoint Web服務
- 記錄代碼時不通過本地機器工作正常工作直接到Web服務器
- 模擬在web.config文件中啓用(但如果你把它關掉你沒有錯誤,但你也得不到任何的物品帶回從SharePoint)
- 認證模式在web.config文件設置在窗口
- 如果我輸出WindowsIdentity.GetCurrent.name並禁用getlistitems調用我可以看到,它通過服務器或本地機器訪問時明確地具有我的詳細信息。
任何想法爲什麼會發生這種情況?