Asp.Net WebApi2 Enable CORS not working with AspNet.WebApi.Cors 5.2.3

后端 未结 11 535
庸人自扰
庸人自扰 2020-11-27 11:06

I tried to follow the steps at http://enable-cors.org/server_aspnet.html to have my RESTful API (implemented with ASP.NET WebAPI2) work with cross origin requests (CORS Enab

11条回答
  •  再見小時候
    2020-11-27 11:59

    Hope this helps someone in the future. My problem was that I was following the same tutorial as the OP to enable global CORS. However, I also set an Action specific CORS rule in my AccountController.cs file:

    [EnableCors(origins: "", headers: "*", methods: "*")]
    

    and was getting errors about the origin cannot be null or empty string. BUT the error was happening in the Global.asax.cs file of all places. Solution is to change it to:

    [EnableCors(origins: "*", headers: "*", methods: "*")]
    

    notice the * in the origins? Missing that was what was causing the error in the Global.asax.cs file.

    Hope this helps someone.

提交回复
热议问题