2011-09-30 37 views
0

所以我做了一個簡單的web表單,在iis的windows auth中設置。然後我將它部署在我的服務器上,並嘗試登錄。它提示我一個登錄框,我輸入了我的信息,看起來很喜歡它在活動目錄中正常工作。獲取用戶名asp.net windows auth

,如果我輸入一些錯誤它不會工作等

很顯然,我需要知道誰在登錄的用戶

Response.Write(HttpContext.Current.User.Identity.Name.ToString()); 

,我發現這個在其他線程,但它不會爲我工作。 ..

我如何獲取登錄框中填寫的信息?

回答

2

如果您在使用asp.netmembership提供商就可以得到當前登錄用戶

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); 

User.Identity.IsAuthenticated 

可用於識別用戶是否登錄成功與否

+0

Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent()。Name.ToString());返回我AUTORITE NT \ SERVICERÉSEAU,編輯,這不是我用來登錄的用戶。我使用davetest – Dave

+0

使用此獲取用戶名User.Identity.Name此外,本文獲得有關此http://social.msdn的有用信息.microsoft.com/Forums/en/pex/thread/2ea4be48-5f5d-46b4-9aca-d9a9531f0e33 –

+0

此方法適用於我。設置''_didn't_。實際上,將impersonate設置爲true會爲我提供NT AUTHORITY \ IUSR,這是默認的匿名IIS用戶。 – bvgheluwe