Identity Server 4 Cors 问题

Identity Server 4 Cors Issue

我使用 IdentityServer4 在 .Net Core 2.0 中创建了一个令牌服务器。但是,我 运行 关注 Plesk 上的 cors 问题(针对 windows),但不关注本地问题。我看到一条错误消息:

Failed to load https://www.mywebsite.com/.well-known/openid-configuration: Redirect from 'https://www.mywebsite.com/.well-known/openid-configuration' to 'https://mywebsite.com/.well-known/openid-configuration' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://stgapp.mywebsite.com' is therefore not allowed access.

我在启动时像这样配置了 Cors:

services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
{
    builder.AllowAnyOrigin()
           .AllowAnyMethod()
           .AllowAnyHeader()
           .AllowCredentials();
}));
public void Configure(IApplicationBuilder app)
{
    app.UseCors("MyPolicy");
}

从 IdentityServer 我已经 AllowAll Origins 只是为了得到这个测试 运行

var loggerFactory = new LoggerFactory();
var identityServerCors = new DefaultCorsPolicyService(loggerFactory.CreateLogger<DefaultCorsPolicyService>())
{
    AllowAll = true
};

但我仍然收到 cors 错误。有谁知道我还能做些什么来解决这个问题?

我真的花了一个星期才修好。我不确定这是 IDSVR4 还是我的浏览器中的错误,但事实证明 Plesk 默认配置了来自 http://www.mywebsite.com -> http://mywebsite.com 的永久重定向。因此,当我的弹出窗口加载时,我总是收到 cors 错误。删除重定向解决了问题