要解决“ASP.NET Core 3.1 + CORS + Windows Authentication = 401 未经授权”的问题,可以按照以下步骤进行:
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
services.AddAuthentication(IISDefaults.AuthenticationScheme);
app.UseCors("AllowAllOrigins");
app.UseAuthentication();
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class MyController : ControllerBase
{
// your actions here
}
这样应该就能解决“ASP.NET Core 3.1 + CORS + Windows Authentication = 401 未经授权”的问题了。
上一篇:Asp.net core 3.1 + Angular DNS查询错误 - 前端和后端无法通信
下一篇:ASP.Net Core 3.1 + Identity Server 4中的JWT Bearer Token无法工作