我想從名爲SV-REQ的服務器上的ASP.Net頁面對另一個稱爲SV-RES的IIS7服務器做HttpWebRequest。當我將SV-RES上的IIS設置爲使用Digest,Basic或Negotiate並對憑證緩存對象進行更改以使用適當的方法時,代碼執行得很好,並且我從SV-RES獲得有效的響應,以確認用戶憑證是正確的。但是,當我將IIS設置爲在SV-RES上使用「Windows身份驗證」時,如果在憑證緩存對象中使用NTLM,則會返回401錯誤。HttpWebRequest通過HTTPS與NTLM不起作用
我真的很茫然,如果有人有關於如何使這項工作的信息,將不勝感激。
注意:正在執行此代碼的服務器正在通過HTTP進行匿名身份驗證。通過HTTPS獲取請求的服務器是NTLM(如前所述),如下面的代碼所示。
這是正在執行的SV-REQ上的代碼。 SV-REQ是IIS7並且配置爲ASP.Net 2.0
Dim credCache As CredentialCache = New CredentialCache()
Dim mUri As Uri = New Uri("https://sv-res.my-domain-here.com/default.htm")
Dim mreq As HttpWebRequest = WebRequest.Create(mUri.ToString)
credCache.Add(mUri, "NTLM", New NetworkCredential(muser, mpass, mdomain))
mreq.Credentials = credCache
Dim mres As HttpWebResponse = mreq.GetResponse
這是我從上面的代碼中從SV-RES返回的錯誤。 SV-RES也是IIS7配置爲ASP.Net 2.0
The remote server returned an error: (401) Unauthorized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized. Source Error: Line 31: credCache.Add(mUri, "NTLM", New NetworkCredential(muser, mpass, mdomain)) Line 32: mreq.Credentials = credCache Line 33: Dim mres As HttpWebResponse = mreq.GetResponse Line 34: Dim sr As StreamReader = New StreamReader(mres.GetResponseStream()) Line 35: txtResult.Text = sr.ReadToEnd() Source File: C:\inetpub\httproot\contentscan.aspx.vb Line: 33 Stack Trace: [WebException: The remote server returned an error: (401) Unauthorized.] System.Net.HttpWebRequest.GetResponse() +1126 contentscan.Page_Load(Object sender, EventArgs e) in C:\inetpub\httproot\contentscan.aspx.vb:33 System.Web.UI.Control.OnLoad(EventArgs e) +132 System.Web.UI.Control.LoadRecursive() +66 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
我知道這很明顯,但是您是否檢查了您實際發送憑據的用戶是否被授權? – 2009-08-12 18:26:02