For the past 2 hours I'm trying to enable CORS in my project.
Things i tried and did not work:
In WebApiConfig.cs
config.EnableCors();
In MyController.cs
[EnableCors(origins: "*", headers: "*", methods: "*")]
https://www.iis.net/downloads/microsoft/iis-cors-module
downloaded and installed. After that i tried to follow the instructions in the references yet no positive result.
How do I enable it?!
If it matters, for my client I'm using React+axios.
I'm stupid, the solution was simple:
Add those two lines to your webApiConfig.cs :
var cors = new System.Web.Http.Cors.EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
Important : DO NOT combine two solutions because it will cause a "Too much cors" problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.