Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net Core Web API - Current user & Windows Authentication

We have following technical stack in our application AngularJS2 Asp.Net Core API SQL Server

Now we need to store User Name for the Logged in User in table during Create/Edit for given item i.e. in Core API.

We have tried with

  • WindowsIdentity.GetCurrent().Name, it gives IIS APPPOOL\Asp.netCore
  • HttpContext.User.Identity gives null value

I get User Name with WindowsIdentity while working with Visual Studio, but with IIS, it gives value as Asp.Netcore i.e. pool name

Windows Authentication is enabled and Anonymous Authentication is disabled

Using IIS Version 6.1

Am I missing anything?

like image 810
Manish Joisar Avatar asked Feb 10 '17 14:02

Manish Joisar


People also ask

How do I get current user in .NET core Web API?

Simple way that works and I checked. private readonly UserManager<IdentityUser> _userManager; public CompetitionsController(UserManager<IdentityUser> userManager) { _userManager = userManager; } var user = await _userManager. GetUserAsync(HttpContext. User);

How can get current 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 I get current UserName in asp net?

Use the UserDomainName property to obtain the user's domain name and the UserName property to obtain the user name. On Unix platforms the UserName property wraps a call to the getpwuid_r function. If an ASP.NET application runs in a development environment, the UserName property returns the name of the current user.

How do I find HttpContext current user identity name?

Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an . aspx page without using the fully qualified class reference to HttpContext. For example, you can use User.Identity.Name to get the name of the user on whose behalf the current process is running.


1 Answers

Do you have the forwardWindowsAuthToken set to true in the web.config?

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true"/>
like image 192
Daboul Avatar answered Oct 10 '22 02:10

Daboul