2016-08-22 151 views
8

我的Asp.Net Core mvc Web應用程序需要Windows身份驗證。在DEVELOPPEMENT,在IIS Express中,一切工作正常得益於此設置Asp.Net核心MVC應用程序IIS中的Windows身份驗證

launchSettings.json

"iisSettings": { 
    "windowsAuthentication": true, 
    "anonymousAuthentication": false, 
    "iisExpress": { 
     "applicationUrl": "http://localhost:61545/", 
     "sslPort": 0 
    } 
    } 

當部署到IIS,我得到一個空白頁。請求我的網站獲得500錯誤代碼。

我試圖將此配置添加到Startup.cs中,如here所述,但未成功。

services.Configure<IISOptions>(options => { 
     options.ForwardWindowsAuthentication = true; 
    }); 

當我直接在IIS中查看身份驗證參數時,會激活Windows身份驗證。

我發現有一篇文章談論一個名爲Microsoft.AspNetCore.Server.WebListener的軟件包,其他一些關於實現自定義中間件的文章。我無法想象這個基本功能需要付出很多努力才能工作。我錯過了什麼嗎?

+0

您確定因身份驗證而發生錯誤嗎?如果是的話什麼是錯誤信息? –

+0

你的FREB日誌裏有什麼? https://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis – blowdart

+0

您可以嘗試在IIS管理器中處理應用程序池標識:http ://www.iis.net/learn/manage/configuring-security/application-pool-identities –

回答

12

launchSettings.json文件只被VS使用。當你發佈你的應用程序(或運行沒有VS)launchSettings.json沒有被使用。當您使用IIS/IISExpress運行時,您只需確保您的web.config具有正確的設置。在你的情況下,web.config中的forwardWindowsAuthToken屬性丟失或設置爲false。它必須設置爲true以使Windows身份驗證正常工作。發佈之前的示例web.config將如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <handlers> 
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> 
    </handlers> 
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true"/> 
    </system.webServer> 
</configuration> 
+2

這是非常有用的,謝謝你的信息。如果它不存在,您可能需要手動創建web.config文件,這發生在我使用VS 2017上,如下所述:[https://developercommunity.visualstudio.com/content/problem/26751/publish-aspnet -core到IIS-與 - 窗口authentica.html](https://developercommunity.visualstudio.com/content/problem/26751/publish-aspnet-core-to-iis-with-windows-authentica.html) –

1

您需要在項目目錄中檢查web.config。這個設置對我有幫助。

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <handlers> 
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> 
    </handlers> 
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true"/> 
    <security> 
     <authentication> 
     <anonymousAuthentication enabled="false" /> 
     <windowsAuthentication enabled="true" /> 
     </authentication> 
    </security> 
    </system.webServer> 
</configuration> 
相關問題