CORS is not working in web api with OWIN authentication

前端 未结 5 615
花落未央
花落未央 2020-12-05 00:36

In my application i am using web api with token based authentication with CORS support, but when client request for the token, an error occured due to CORS (Cross-Origin Re

5条回答
  •  不知归路
    2020-12-05 01:39

    Be sure you've got only

    app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

    configured, and not also the old style 'config.EnableCors()' in your Global.asax or WebApiConfig. Furthermore: place the above statement as the first one in your owin Startup class. Yes that really makes a difference, setting it later can also cause cors to not work.

    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    
            ... etc
    

提交回复
热议问题