在aspx頁面中,我獲取了具有函數Request.LogonUserIdentity.Name
的Windows用戶名。該函數返回格式爲「domain \ user」的字符串。如何在沒有域名的情況下獲取用戶名
是否有一些功能只獲取用戶名,而不訴諸於IndexOf
和Substring
,像這樣?
public static string StripDomain(string username)
{
int pos = username.IndexOf('\\');
return pos != -1 ? username.Substring(pos + 1) : username;
}
Request.LogonUserIdentity.Name對於登錄表單來說工作得很好,以便在創建使用LDAP的登錄表單時在域上獲取登錄用戶的用戶名。其他的需要Windows認證彈出我相信。 – RandomUs1r 2014-09-09 19:33:39