我想从名为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