asp.net认证问题基本/ windows

时间:2012-08-08 13:36:24

标签: c# asp.net authentication iis basic-authentication

我正在查看一个内部网站点(不是由我开发的),它启用了基本身份验证。 它需要更改为Windows身份验证,我已经在IIS中完成了这项工作。

基本上我已经安装了Visual Studio 2010远程调试器来检查为什么它使用基本身份验证工作正常,但是当更改为Windows时它没有。

它挂在try的第一行,错误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服务器上运行该站点时,它工作正常。

0 个答案:

没有答案