2011-05-25 54 views
3

本地主機我的用戶名是 'MTA' 調用此代碼時:如何在ASP.net中獲得客戶機用戶登錄?

string opl = HttpContext.Current.User.Identity.Name.ToString(); 
TextBox1.Text = opl.Substring(opl.IndexOf(@"\") + 1); 

或本規範:

string opl = System.Environment.UserName.ToString(); 
TextBox1.Text = opl.Substring(opl.IndexOf(@"\") + 1); 

但發佈和訪問從Windows Server網站之後。我的用戶名現在是'SRVCMAN'。

+0

什麼是你想怎麼辦? – 2011-05-25 10:26:37

+0

我只需要知道正在使用我的網站的用戶。 – SamekaTV 2011-05-25 10:33:52

+0

但是不同的人可以在不同的設備上擁有相同的用戶名。在這裏獲取用戶名有什麼好處? – 2011-05-25 10:36:56

回答

3
+0

我不這麼認爲他在談論Windows驗證。 – 2011-05-25 10:48:29

+0

請注意,要實現上述,您需要將您的網站配置爲在IIS中使用集成安全性。 – DaveRead 2011-05-25 10:52:16

+0

@Muhammad阿赫塔爾:他想給用戶一個企業沒有讓他提供他的用戶名和密碼進行身份驗證。我認爲Windows身份驗證對於這種情況是一個不錯的選擇。 – 2011-05-25 10:52:45

4

對於這項工作進入IIS點擊Authentication和禁用Anonymous Authentication並啓用Windows Authentication

,然後使用此代碼:

var ident = (System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity; 
If(!ident.IsAnonymous && ident.IsAuthenticated) 
{ 
    var loginUsername = ident.Name; 
} 
+0

我在哪裏可以找到呢? – SamekaTV 2011-05-25 10:54:36

+0

找到什麼? IIS? – Magnus 2011-05-25 14:28:05

+0

我在哪裏可以找到身份驗證? – SamekaTV 2013-10-29 13:39:16

4
// will return the host name making the request 

    string s = Request.ServerVariables["REMOTE_HOST"] ; 
----------------------------------------------------------------- 
    // will return the computer name 

    string s = Request.ServerVariables["SERVER_NAME"] ; 
----------------------------------------------------------------- 
    //will return Windows account for the user. 

    string s = Request.ServerVariables["AUTH_USER"] ; 
----------------------------------------------------------------- 

我想你試圖讓信息像這樣:

IIS Server Variables

相關問題