【问题标题】:Asp.Net core MVC application Windows Authentication in IISIIS 中的 Asp.Net 核心 MVC 应用程序 Windows 身份验证
【发布时间】:2016-08-22 16:03:41
【问题描述】:

我的 Asp.Net Core mvc web 应用程序需要 Windows 身份验证。在开发中,在 IIS Express 上,由于此设置,一切正常

launchSettings.json

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

部署到 IIS 时,我得到一个空白页。对我的站点的请求收到 500 错误代码。

按照here 的说明,我尝试将此配置添加到 Startup.cs,但没有成功。

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

当我直接在 IIS 中查看身份验证参数时,Windows 身份验证被激活。

我发现一些帖子讨论了一个名为 Microsoft.AspNetCore.Server.WebListener 的包,还有一些帖子讨论了实现自定义中间件。我无法想象这个基本功能需要付出那么多努力才能工作。我错过了什么吗?

【问题讨论】:

标签: iis asp.net-core windows-authentication


【解决方案1】:

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】:

对我来说,我必须添加一行

services.AddAuthentication(IISDefaults.AuthenticationScheme);

在方法ConfigureServicesStartup.cs

我的应用允许 Windows 和匿名用户。

https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#windows-authentication-httpsys--iisintegration

【讨论】:

    【解决方案3】:

    您需要检查项目目录中的 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>
    

    【讨论】:

    • 这是 asp.net core 2.1 中的无效配置
    猜你喜欢
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 2020-07-16
    • 2011-08-14
    • 2022-11-29
    • 1970-01-01
    相关资源
    最近更新 更多