我有以下代码:
protected void Page_Load(object sender, EventArgs e)
{
string infors = "";
System.Security.Principal.WindowsIdentity usr = System.Security.Principal.WindowsIdentity.GetCurrent();
infors += "Authentication Type: " + usr.AuthenticationType + "<br>";
infors += "Name: " + usr.Name + "<br>";
infors += "IsAnonymous: " + usr.IsAnonymous + "<br>";
infors += "IsAuthenticated: " + usr.IsAuthenticated + "<br>";
infors += "IsGuest: " + usr.IsGuest + "<br>";
infors += "IsSystem: " + usr.IsSystem + "<br>";
infors += "Token: " + usr.Token.ToString() + "<br>";
Label1.Text = infors;
}
但是,它一直在Name
部分
Authentication Type: NTLM Name: SECTOR_A\Administrator IsAnonymous: False IsAuthenticated: True IsGuest: False IsSystem: False Token: 564
我的IIS设置为:
Anonymous Authentication - Disabled ASP.NET Impersonation - Enabled Basic Authentication - Enabled Windows Authentication - Enabled
我甚至通过设置为Prompt for user name and password
来更改IE设置,如下所示
======但是======
虽然我在打开Web应用程序时在弹出登录消息中输入域用户名和密码,但它没有给我正确的Name
部分,该部分应为SECTOR_HQ\Jack
。
所以我想问一下我的代码和配置中是否有任何遗漏。
======添加了Web.config ======
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
======应用程序池信息======
.NET Framework Version: v4.0 Managed Pipeline Mode: Classic Identity: ApplicationPoolIdentity
答案 0 :(得分:0)
尝试在配置中添加身份验证部分:
<system.web>
...
<authentication mode="Windows"/>
<identity impersonate="true"/>
...
</system.web>
您可以在此处找到更多详细信息: