whats the difference between Environment.UserName
; and System.Security.Principal.WindowsIdentity.GetCurrent().Name
; and HttpContext.Current.User
?
As per my understanding HttpContext.Current.User
returns Logged in user , System.Security.Principal.WindowsIdentity.GetCurrent().Name
returns the identuty under which code is running. But What is the use of Environment.UserName
; ?
Environment.UserName
returns just the user name string of the logged into the Windows OS user - ie 'JohnDoe'
System.Security.Principal.WindowsIdentity.GetCurrent().Name
returns NetBIOS user name of the logged into the Windows OS user - ie 'Fabrikam\\JohnDoe'
HttpContext.Current.User
returns the user object of the logged into the website user, given the website is leveraging the membership system. To get the username string you need to navigate through the Identity property:
string userName = HttpContext.Current.User.Identity.Name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.