0
TLDR:1服务器,IIS,两个网站,失踪CORS标头在预检响应IIS服务器托管API和角2应用无CORS发送
> http://myserver:88 // This is my angular site
> http://myserver:8888 // This is my .NET CORE API
背景:
我已经开发的ASP。 NET CORE API和一个Angular Web应用程序。 我有他们与IIS在同一台服务器上托管。他们是两个不同的'网站'。
我有一个CORS问题。我的力,发送响应报头,像这样....
现在在我的登录终点,我需要自定义页眉。因此,需要预检响应.. Chrome会显示这个..
然后第二天调用显示了这一点。
我不知道我在做什么错在这里...
这是我的CORS如何设置看起来的API中。
public void ConfigureServices(IServiceCollection services)
{
string[] origins = new [] { "http://myServer:88" }; // PORT TO HOSTED ANGULAR SITE
services.AddCors(options => {
options.AddPolicy("AllowSpecificOrigin", builder =>
builder.WithOrigins(origins)
.WithMethods("GET", "POST")
.WithHeaders("accept", "content-type", "origin", "username", "password")
.AllowCredentials()
);
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCors("AllowSpecificOrigin");
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
我在try catch中封装了我的端点,并在catch中返回异常e。数据库连接不正确,并引发错误。 这个异常以某种方式触发了CORS错误。 – jriver27