C# 无法获取用户凭据(Windows身份验证)
以下是web配置: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
<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身份验证-已禁用
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;
}