Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out the name of currently logged in user in ASP.NET?

Tags:

c#

.net

asp.net

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?

like image 231
Dmitrii Pisarenko Avatar asked May 16 '14 13:05

Dmitrii Pisarenko


People also ask

How can we get logged in user details in asp net core?

You can create a method to get the current user : private Task<ApplicationUser> GetCurrentUserAsync() => _userManager. GetUserAsync(HttpContext. User);

How can get current logged in user in ASP NET MVC?

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 .

What is HttpContext user identity name?

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.


1 Answers

You have to set the authentication in IIS to Windows Authentication (and probably disable all others):

enter image description here

Go to:

  • Website
  • IIS - Authentication
  • Edit according your wishes
like image 55
Patrick Hofman Avatar answered Oct 06 '22 00:10

Patrick Hofman