I have read through a lot of the stuff over enabling CORS in my web api.
I installed the NuGet Package and added this line to my WebApiConfig.cs:
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
I can't actually compile my code though because it says it does not have a definition for EnableCORS
.
So... what is wrong? (Yes, I did install the CORS package using this:
Install-Package Microsoft.AspNet.WebApi.Cors
To solve this problem you need to do like this
System.Web.Http.Cors
add the following line code inside the Register method of the WebApiConfig class.
config.EnableCors();
Add the following attribute in your controller(s)
[EnableCors(origins: " ", headers: " ", methods: "*", SupportsCredentials = true)]
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.