簡體   English   中英

ASP.NET用戶身份

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM