Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法获取用户凭据(Windows身份验证)_C#_.net_Windows_Authentication_Iis - Fatal编程技术网

C# 无法获取用户凭据(Windows身份验证)

C# 无法获取用户凭据(Windows身份验证),c#,.net,windows,authentication,iis,C#,.net,Windows,Authentication,Iis,以下是web配置: <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Windows" /> <authorization> </authorization> <identity impersonate="true" /> </system.we

以下是web配置:

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />

    <authorization>

    </authorization>
    <identity impersonate="true" />



  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true" />
        <security>
            <authentication>
                <windowsAuthentication enabled="true" >
                    <providers>
                        <clear />
                        <add value="NTLM" />
                    </providers>
                </windowsAuthentication>
                <anonymousAuthentication enabled="false" />
            </authentication>
        </security>
  </system.webServer>
结果(需要的是域\用户名):


站点位于iis服务器6.0上,除身份模拟和windows身份验证外,所有功能都已禁用。

我认为您获得此用户是由于身份模拟参数。 将参数更改为

identity impersonate=false
并检查您是否拥有该帐户

这对我来说很有效: web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
    <identity impersonate="false" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>
IIS设置:

  • 匿名身份验证-禁用
  • ASP.NET即兴表演-已禁用
  • 表单身份验证-已禁用
  • Windows身份验证-已禁用
就算我跑的是7.5

屏幕截图(在IIS上运行,而不是通过VS):


Hi,我照你说的做了,但我仍然看到:Anonymous/////NETWORK service修改后你是否重新启动了IIS服务?尝试直接在IIS配置中设置参数,之后将生成web.config。一旦获得所有好的参数ID,您将尝试使用“User.Identity.Name”而不是LogonUserIdentity?仍然返回:Anonymous//NETWORK SERVICE。由于某些原因,我无法让它使用用户的凭据而不是服务器的凭据。哦,每次更改后,我都会重新启动网站,以防万一(毕竟是Microsoft):)我复制了您的所有设置,但仍然收到相同的错误结果:(
identity impersonate=false
<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
    <identity impersonate="false" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>
protected void Page_Load(object sender, EventArgs e)
{
    WindowsIdentity identity = HttpContext.Current.Request.LogonUserIdentity;

    string sLoginID = identity.Name.ToString();
    TextBox1.Text = sLoginID;
}