Http Response headers missing in chrome, but with Postman they show up

后端 未结 3 1076
别跟我提以往
别跟我提以往 2021-01-02 14:55

When calling my REST Service in Angular, there are no response headers.

Login method in Angular



        
3条回答
  •  失恋的感觉
    2021-01-02 15:50

    I used the following solution to allow my custom header in Owin self-hosted web api

    using Owin;
    using Microsoft.Owin.Cors;
    using System.Threading.Tasks;
    using System.Web.Cors;
    
    namespace App.Web.App_Start
    {
        public static class CorsConfig
        {
            public static void Configure(IAppBuilder app)
            {
                var allowedOrigins = "comma,separated,list,of,origins";
                var corsPolicy = new CorsPolicy
                {
                    AllowAnyHeader = true,
                    AllowAnyMethod = true,
                    AllowAnyOrigin = false,
                    SupportsCredentials = true
                };
    
                corsPolicy.ExposedHeaders.Add("Custom-Header");
    
                foreach (string origin in allowedOrigins.Split(','))
                    corsPolicy.Origins.Add(origin);
    
                app.UseCors(new CorsOptions
                {
                    PolicyProvider = new CorsPolicyProvider
                    {
                        PolicyResolver = context => Task.FromResult(corsPolicy)
                    }
                });
            }
    
        }
    
    }
    

    I call the method like this CorsConfig.Configure(app); // app is Owin.IAppBuilder

提交回复
热议问题