2017-08-28 35 views
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問題。我的力,發送響應報頭,像這樣....

enter image description here

現在在我的登錄終點,我需要自定義頁眉。因此,需要預檢響應.. Chrome會顯示這個..

I get the 'Access-Control-Allow-Origin' header

然後第二天調用顯示了這一點。

enter image description here enter image description here

我不知道我在做什麼錯在這裏...

這是我的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?}"); 
      }); 
+0

我在try catch中封裝了我的端點,並在catch中返回異常e。數據庫連接不正確,並引發錯誤。 這個異常以某種方式觸發了CORS錯誤。 – jriver27

回答

0

我的CORS設置沒有問題。這是由於我的端點引發了異常。我希望這可以幫助別人。