CORS POST Requests not working - OPTIONS (Bad Request) - The origin is not allowed

后端 未结 5 1526
不思量自难忘°
不思量自难忘° 2020-12-13 19:01

I\'m having a lot of trouble getting a cross domain POST request to hit an Api controller in the latest beta 2 release.

Chrome (and other browsers) spit out:

5条回答
  •  心在旅途
    2020-12-13 19:45

    if you use OAuth Authorization . request not go direct to web api. You need to enable OWIN CORS support for that endpoint.

    How i do on my site: Install owin cors

    Install-Package Microsoft.Owin.Cors
    

    Note: please not use : Install-Package Microsoft.AspNet.WebApi.Cors

    In file Startup.Auth.cs

     //add this line
                app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    
                // Enable the application to use bearer tokens to authenticate users
                app.UseOAuthBearerTokens(OAuthOptions);
    

提交回复
热议问题