I follow the step below to solve CORS issue.
1.Install Microsoft.AspNet.WebApi.Cors with nuget.
2.Add code below in WebApiConfig.cs
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
Most of API will work. Only oData API will still have CORS issue.
How to resolve CORS problem in oData API?
edit:
After input the code below in Global.asax and it works.
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.Path.Contains("odata/") && Context.Request.HttpMethod == "OPTIONS")
{
Context.Response.AddHeader("Access-Control-Allow-Origin", Context.Request.Headers["Origin"]);
Context.Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
Context.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST PUT, DELETE, OPTIONS");
Context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
Context.Response.End();
}
}