No HTTP resource error when doing PUT/POST [CORS issue - AngularJS + Web API 2]

前端 未结 2 1162
我在风中等你
我在风中等你 2021-01-13 13:13

There are so many questions in SO similar to this, but none have fixed my issue.

I\'ve have an angularjs website hosted at http://localhost:49595 and I\

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 14:08

    Besides the config option config.EnableCors(); in your Register method you need to enable CORS in your controller by using [EnableCors] attribute along with the declaration of the controller, here is an example how I do it:

     [EnableCors(origins: "http://localhost:49595", headers: "*", methods: "*")]
     public class ValuesController : ApiController
     {
     ...
    

提交回复
热议问题