具有 SPA 站点 CORS 问题的 IdentitySever

IdentitySever with SPA Site CORS Issue

我有一个 asp 核心 angular 2 SPA 网站,它使用 oidc 客户端向 IdenityServer 进行身份验证。

我尝试了 javascript walthrough example 的 spa 认证。

为了模拟不同的域,spa 站点在 http://localhost:5000 上运行,身份服务器在 http://localhost:7890

上运行

在 IdentityServer 中,我将 AllowedCorsOrigins 添加到客户端配置。

AllowedCorsOrigins = new List<string>
{
     "http://localhost:5000"
}

但是当我触发重定向时我仍然遇到跨域问题

XMLHttpRequest cannot load http://localhost:7890/identity-server/.well-known/openid-configuration. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access. The response had HTTP status code 404.

我错过了什么?

The response had HTTP status code 404.

这可能是错误消息中最重要的部分。您启用了 CORS,但大概只针对实际存在的页面。

你 URL 错了。