2017-02-10 146 views
3

我们已经按照我们的应用程序 AngularJS2 Asp.Net核心API SQL Server技术堆栈Asp.net核心Web API - 当前用户的Windows身份验证

现在,我们需要存储用户名登录的用户在创建/编辑期间在给定项目,即在核心API。

我们已经与

  • WindowsIdentity.GetCurrent()。名称试过了,它给IIS APPPOOL \ Asp.netCore
  • HttpContext.User.Identity给空值

我得到用户在使用Visual Studio时与WindowsIdentity同名,但使用IIS时,其值为Asp.Netcore,即池名称

启用Windows身份验证,匿名Aut hentication被禁用

使用IIS版本6.1

我错过了什么吗?

+0

我有同样的问题,但与生产iis 7.5。在我的开发机器上,我得到了我的ntld,但是当我部署到prod时,我仍然得到应用程序池名称。部署时没有launchSettings.json文件。部署到生产时是否有同样的问题? – freddoo

+0

更新 - 我改变我的System.Security.Principal.WindowsIdentity.GetCurrent()。名称为User.Identity.Name现在它的工作。我以前没有工作。 – freddoo

回答

3

我环顾四周,建议使用Windows身份验证创建Asp.Net Core WebApi应用程序。

所以,当我使用Windows身份验证创建了Asp.Net Core WebApi时,它工作并获取了User.Identity对象中的值。

所以我创建2级的应用,即一个使用Windows身份验证而另一个没有,再对比所有文件,发现变化以下文件

  • forwardWidnowsAuthToken - 诚然,这是以前试过,但问题并没有解决,同被Daboul建议
  • launchSettings.json,集 “windowsAuthentication”:真& “anonymousAuthentication”:假

这样做后,我能值User.Identi ty对象。


的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> 
+1

在我的情况是反转,我的launchsettings.json文件是正确的,但IIS设置不是按给定的答案设置anonymousAuthentication = false在这两个地方,它为我工作。 感谢您节省我的时间:-) –

2

您是否已将web.config中的forwardWindowsAuthToken设置为true?

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

在Windows Server 2012 R2/IIS 8.0,即使在网络设置forwardWindowsAuthToken = TRUE后。配置,User.Identity.Name没有返回用户名,但IIS APPPOOL,以解决我在下面改变的问题;

  1. 转到IIS
  2. 打开配置编辑器
  3. 变化。第web应用系统。web服务器/ serverRuntime中
  4. 变化authenticatedUserOverride到UseAuthenticatedUser(对我来说它被设为UseWorkerProcessUser)

有关进一步详情,请参阅以下链接; https://blogs.iis.net/jaroslad/what-does-the-authenticateduseroverrideuser-do

相关问题