[英]ASP.NET User Identity
Environment.UserName
和有什么不一樣? 和System.Security.Principal.WindowsIdentity.GetCurrent().Name
; 和HttpContext.Current.User
?
根據我的理解, HttpContext.Current.User
返回登錄的用戶, System.Security.Principal.WindowsIdentity.GetCurrent().Name
返回在其下運行代碼的身份。 但是Environment.UserName
的用途是什么? ?
Environment.UserName
僅返回已登錄Windows OS用戶的用戶名字符串-即'JohnDoe'
System.Security.Principal.WindowsIdentity.GetCurrent().Name
返回已登錄Windows OS用戶的NetBIOS用戶名-即“ Fabrikam \\ JohnDoe”
如果網站正在利用成員資格系統,則HttpContext.Current.User
返回已登錄網站用戶的用戶對象。 要獲取用戶名字符串,您需要瀏覽Identity屬性:
string userName = HttpContext.Current.User.Identity.Name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.