我正在查看一个 Intranet 站点(不是我开发的),它启用了基本身份验证。它需要更改为 Windows 身份验证,我已经在 IIS 中完成了此操作。
基本上我已经安装了 Visual Studio 2010 远程调试器来检查为什么它使用基本身份验证可以正常工作,但是当更改为 Windows 时它不会。
它挂在尝试的第一行,错误 401 未经授权:
oReq.ContentType = "application/x-www-form-urlencoded";
oReq.Method = "POST";
// Set the script timeout to a desired value. Timeout value is specified in milliseconds.
oReq.Timeout = 60000;
WindowsIdentity wId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsIdentity wIdb4 = WindowsIdentity.GetCurrent();
string name = wIdb4.Name;
WindowsImpersonationContext wIdCon = wId.Impersonate();
// Set credentials to use for this request.
oReq.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
Stream oDataStream = oReq.GetRequestStream();
// Use EncodeParam to enocde the parameters passed in the URL
String sParam = "...";
UTF8Encoding encoding = new UTF8Encoding();
Byte[] Buffer = encoding.GetBytes(sParam);
oDataStream.Write(Buffer, 0, Buffer.Length);
oDataStream.Close();
try
{
HttpWebResponse oResp = (HttpWebResponse)oReq.GetResponse();
....
}
没有意义,为什么它会通过基本身份验证而不是 Windows?此外,当我在本地机器 asp.net 服务器上运行该站点时,它工作正常。