I have an ASP.NET application, which runs on machine 1.
When a user access that page from machine 2, I want to find out the user name, under which he or she is logged in on machine 2.
I tried to use
Request.LogonUserIdentity.Name
Page.User.Identity.Name
((WindowsIdentity)HttpContext.Current.User.Identity).Name
((WindowsIdentity)HttpContext.Current.User.Identity).User
Request.LogonUserIdentity.User
but it doesn't work.
Request.LogonUserIdentity.Name
returns NT AUTHORITY\IUSR
, Request.LogonUserIdentity.User
- S-1-5-17
, all others - empty strings. NT AUTHORITY\IUSR
is the user on the machine, on which the web application runs, not the user on the client machine.
In web.config
I disabled impersonation using
<authentication mode="Windows"/>
<identity impersonate="false"/>
What can I do in order to get the user name of the user, who accesses the web page?
You can create a method to get the current user : private Task<ApplicationUser> GetCurrentUserAsync() => _userManager. GetUserAsync(HttpContext. User);
If you need to get the user from within the controller, use the User property of Controller. If you need it from the view, I would populate what you specifically need in the ViewData , or you could just call User as I think it's a property of ViewPage .
It just holds the username of the user that is currently logged in. After login successful authentication, the username is automatically stored by login authentication system to "HttpContext.Current.User.Identity.Name" property.
You have to set the authentication in IIS to Windows Authentication (and probably disable all others):
Go to:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With