Web Api 2 Preflight CORS request for Bearer Token

后端 未结 4 1224
天命终不由人
天命终不由人 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 18:00

    I hope this is able to help somebody out there. For me:

    • adding the app.useCors(); LOC did not work.
    • Adding the app.useCors(); LOC worked for other people on my team.

    So I needed a solution that would work across everyone's environments.

    Ultimately what I ended up doing was adding the header and value right into the Web.config with the following (where localhost:9000 is my node application that is serving up angular):

    
        
          
            
            
          
        
      
    

    Then in production you can just change the origin value to the production front-end url.

    If you want CORS enabled for all origins, change the value to "*".

提交回复
热议问题