IIS 基本身份验证配置 .NET Core 2.1 应用程序
IIS Basic Auth Configuration .NET Core 2.1 application
我有一个 .NET Core 2.1 应用程序,它在 IIS 上 运行 配置了基本身份验证和 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 似乎也不支持 Basic Auth。如果有人可以通过一些文档确认这一点,我将不胜感激。
ASP.NET核心模块被设计为只转发Windows认证令牌,
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1
不确定他们是否计划在 .NET Core 2.2 中对此进行更改。
我有一个 .NET Core 2.1 应用程序,它在 IIS 上 运行 配置了基本身份验证和 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 似乎也不支持 Basic Auth。如果有人可以通过一些文档确认这一点,我将不胜感激。
ASP.NET核心模块被设计为只转发Windows认证令牌,
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1
不确定他们是否计划在 .NET Core 2.2 中对此进行更改。