我有以下代碼:無法獲得域用戶
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
我甚至改變IE設置,設置爲Prompt for user name and password
,如下圖所示
======然而======
雖然我進入,在彈出的登錄信息的域用戶名和密碼,當我打開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
你能告訴在web.config中的身份驗證部分? – 2GDev
@ 2GDev,謝謝,我爲您的信息添加了問題。 – Jack
爲什麼不使用'this.User'屬性? –