Web Api 2 Preflight CORS request for Bearer Token

后端 未结 4 1208
天命终不由人
天命终不由人 2020-12-28 17:19

I have a web-app with an AngularJS front-end and a Web Api 2 back-end, and it uses bearer-tokens for authentication.

All is well in FireFox & IE, but with Chrome

4条回答
  •  爱一瞬间的悲伤
    2020-12-28 17:51

    By default - Access-Control-Max-Age: seconds is 0 and your requests not caching.

    Try set it to max value: (Owin selfhost). It solve problem with extra OPTIONS requests

                app.UseCors(new CorsOptions
                {
                    PolicyProvider = new CorsPolicyProvider
                    {
                        PolicyResolver = context => Task.FromResult(new CorsPolicy
                        {
                            AllowAnyHeader = true,
                            AllowAnyMethod = true,
                            AllowAnyOrigin = true,
                            SupportsCredentials = false,
                            PreflightMaxAge = Int32.MaxValue // << ---- THIS
                        })
                    }
                });
    

提交回复
热议问题