Asp.net Core Web API - Current Windows User and Authentication

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

Now we need to save the username for the registered user in the table during creation / editing for this element, that is, in the Core API.

We tried using

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

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

Windows Authentication Enabled and Anonymous Authentication Disabled

Using IIS 6.1

Did I miss something?

+4
3

, Asp.Net Core WebApi Windows.

, Asp.Net Core WebApi, Windows Authentication, , User.Identity.

, 2 , Windows Authentication ,

  • forwardWidnowsAuthToken - , , , Daboul
  • launchSettings.json, "windowsAuthentication": true "anonymousAuthentication": false

User.Identity.


launchSettings.json:

{
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false
    }
}

Web.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore forwardWindowsAuthToken="true" processPath="C:\Program Files\dotnet\dotnet.exe" arguments=".\YourWebsite.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
        <security>
            <authentication>
                <windowsAuthentication enabled="true" />
                <anonymousAuthentication enabled="false" />
            </authentication>
        </security>
  </system.webServer>
</configuration>
+3

forwardWindowsAuthToken true web.config?

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true"/>
+2

Windows Server 2012 R2/IIS 8.0, forwardWindowsAuthToken = true web.config, User.Identity.Name , IIS APPPOOL, , ,

  • - IIS
  • system.webServer/serverRuntime
  • authenticatedUserOverride UseAuthenticatedUser ( UseWorkerProcessUser)

. ; https://blogs.iis.net/jaroslad/what-does-the-authenticateduseroverrideuser-do

0
source

Source: https://habr.com/ru/post/1669386/


All Articles