2016-08-22 152 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> 
相关问题