【问题标题】:IIS Basic Auth Configuration .NET Core 2.1 applicationIIS 基本身份验证配置 .NET Core 2.1 应用程序
【发布时间】:2018-07-26 20:11:51
【问题描述】:

我有一个在 IIS 上运行的 .NET Core 2.1 应用程序,配置了基本身份验证和 Windows 身份验证。 Windows 身份验证按预期工作。当我禁用 Windows 身份验证并仅使用基本身份验证时,应用程序无法按预期工作。它在访问 index.html 页面时提示输入凭据,并在您转到 API 的 swashbuckle UI 时再次提示。当您尝试使用任何 API 端点时,它会提示输入凭据并继续提示输入凭据,就像它不记得用户一样。

我有这个中间件记录正在发生的事情

  public class UserInfoMiddleWare
  {
    private readonly ILogger<UserInfoMiddleWare> _logger;
    private readonly RequestDelegate _next;

    public UserInfoMiddleWare(ILogger<UserInfoMiddleWare> logger, RequestDelegate next)
    {
      _logger = logger;
      _next = next;
    }

    public async Task InvokeAsync(HttpContext context)
    {

      this._logger.LogError("UserInfoMiddleWare!!!!!!");

      try
      {

      var userIdentity = context.User?.Identity;
        this._logger.LogError($"user exists {(userIdentity != null)}");
        var loginName = context.User?.LoginName();
        this._logger.LogError($"LoginName {loginName}");
        var name = userIdentity?.Name;
        this._logger.LogError($"name {name}");

      var identityIsAuthenticated = userIdentity?.IsAuthenticated;
        this._logger.LogError($"identityIsAuthenticated {identityIsAuthenticated}");

        var identityAuthenticationType = userIdentity?.AuthenticationType;
        this._logger.LogError($"identityAuthenticationType {identityAuthenticationType}");
    }
      catch (Exception e)
      {
        this._logger.LogError(e, "bad middleware!");
      }

      await _next(context);

  }

这是我在日志中得到的示例输出

[Error] UserInfoMiddleWare!!!!!!
[Error] user exists True
[Error] LoginName 
[Error] name 
[Error] identityIsAuthenticated False
[Error] identityAuthenticationType 

编辑: 经过阅读后,即使 IIS 是代理,.NET Core 似乎也不支持基本身份验证。如果有人可以通过一些文档确认这一点,我将不胜感激。

【问题讨论】:

    标签: iis .net-core basic-authentication


    【解决方案1】:

    ASP.NET Core 模块设计为仅转发 Windows 身份验证令牌,

    https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1

    不确定他们是否计划在 .NET Core 2.2 中改变这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 2019-06-02
      • 2014-02-05
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      相关资源
      最近更新 更多