Enable CORS for Web Api 2 and OWIN token authentication

后端 未结 3 1083
走了就别回头了
走了就别回头了 2020-12-23 10:22

I have an ASP.NET MVC 5 webproject (localhost:81) that calls functions from my WebApi 2 project (localhost:82) using Knockoutjs, to make the communication between the two p

3条回答
  •  离开以前
    2020-12-23 10:40

    Follow below steps and you will have your API working:

    1. Remove any code like config.EnableCors(), [EnableCors(header:"*"....)] from your API.
    2. Go to startup.cs and add below line

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

    before

        ConfigureAuth(app);
    

    Uou will also need to install Microsoft.owin.cors package to use this functionality

提交回复
热议问题