2017-02-10 145 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

相關問題