首页 文章

通过HTTPS的HttpWebRequest与NTLM无法正常工作

提问于
浏览
2

我试图从名为SV-REQ的服务器上的ASP.Net页面对另一个名为SV-RES的IIS7服务器进行HttpWebRequest . 当我在SV-RES上设置IIS以使用Digest,Basic或Negotiate并对凭证缓存对象进行更改以使用适当的方法时,代码执行正常并且我从SV-RES获得有效响应,确认用户凭据是正确的 . 但是,当我将IIS设置为在SV-RES上使用“Windows身份验证”时,我在凭证缓存对象中使用NTLM时会收到401错误 .

我真的很茫然,如果有人知道如何使这项工作,我将不胜感激 .

注意:正在执行此代码的服务器正在通过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也是为ASP.Net 2.0配置的IIS7

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

1 回答

相关问题