IIS 中的 Asp.Net 核心 MVC 应用程序 Windows 身份验证 [英] Asp.Net core MVC application Windows Authentication in IIS

查看:36
本文介绍了IIS 中的 Asp.Net 核心 MVC 应用程序 Windows 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My Asp.Net Core mvc web application requires Windows Authentication. In developpement, on IIS Express, everything works fine thanks to this setting

launchSettings.json

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

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

When deploying to IIS, I get a blank page. The Request to my site get a 500 error code.

我尝试将此配置添加到 Startup.cs,如here ,没有成功.

I tried to add this configuration to Startup.cs, as explained here , without success.

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

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

When I look into the authentication parameters directly in IIS, Windows Authentication is activated.

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

I found some post talking about a package called Microsoft.AspNetCore.Server.WebListener, others about implementing a custom Middleware. I can't imagine this basic feature needs that much effort to work. Am I missing something ?

推荐答案

launchSettings.json 文件仅供 VS 使用.当您发布应用程序(或在没有 VS 的情况下运行)时,没有使用 launchSettings.json.当您使用 IIS/IISExpress 运行时,您只需要确保您的 web.config 具有正确的设置.在您的情况下,web.config 中的 forwardWindowsAuthToken 属性丢失或设置为 false.它必须设置为 true 才能使 Windows 身份验证工作.发布前的示例 web.config 如下所示:

launchSettings.json file is only used by VS. When you publish your app (or run without VS) launchSettings.json is not being used. When you run with IIS/IISExpress you just need to make sure that your web.config has correct settings. In your case the forwardWindowsAuthToken attribute in the web.config is missing or is set to false. It must be set to true for Windows Authentication to work. A sample web.config before publishing would look like this:

<?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=".logsstdout" forwardWindowsAuthToken="true"/>
  </system.webServer>
</configuration>

这篇关于IIS 中的 Asp.Net 核心 MVC 应用程序 Windows 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆