我已经把我的IS4放在服务器上,让我们调用它
http://test.myis4.com
. 现在,我正试图用一个有角度的应用程序登录它,但是我一直被CORS阻止。angular客户端由一个MVC核心应用程序提供服务,它运行在
http://localhost:5002
港口城市我试图通过在本地主机上运行它来实现这一点。
在IS4服务器上,我尝试在客户端上添加以下内容:
new Client {
// code is omitted
AllowedCorsOrigins = new List<string>() { "http://localhost:5002" }
}
在上述情况下,我仍然得到CORS错误,然后我尝试将其添加到服务目录:
var cors = new DefaultCorsPolicyService(null)
{
AllowedOrigins = { "http://localhost:5002" }
};
services.AddSingleton<ICorsPolicyService>(cors);
services.AddIdentityServer()
//rest omitted
以上仍然给了我相同的CORS错误,我最后一次尝试是通过application builder添加它:
app.UseCors(builder => builder.WithOrigins("http://localhost:5002").AllowAnyHeader());
app.UseIdentityServer();
//rest omitted
最后一次尝试仍然没有成功。我不确定我现在做错了什么。有什么建议吗?