2012-02-22 131 views
0

我有一個內部網站,我需要查看誰登錄到Windows PC,以便他們不需要自己鍵入他們的名稱。從asp.net的Windows登錄獲取用戶

我曾嘗試:

System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; 

string strName = HttpContext.Current.User.Identity.Name.ToString(); 

它工作在我的電腦上,但是當我用它在服務器上沒有。

+0

什麼身份驗證模式是您使用來識別用戶? – SeanCocteau 2012-02-22 12:55:26

回答

0

兩件事情你應該照顧:

  1. 在web.config:`
  2. 要獲取當前用戶,使用此: System.Security.Principal.IPrincipal User = System.Web.HttpContext.Current.User;

,如果你需要什麼更多的PLZ問

0

幫我:

<system.web> 
    <anonymousIdentification enabled="false"/> 
</system.web> 

我能得到用戶的喜歡這個很簡單:

HttpContext.User 
相關問題