Hello
I have a problem with CORS.
I need to call a web service from 2 domains. In my web.config I added headers:
CORS works well, but I don't like * in the Origin. I try do do the same in Application_BeginRequest:
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:3312");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Accepts, Content-Type, Origin, X-My-Header");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "60");
HttpContext.Current.Response.End();
}
When I check headers in the browser they looks the same but I have CORS error "
The Same Origin Policy disallows reading the remote resource..."
What to do to get it working?
Madan ShekarPosted Oct 26, 2018, 7:47 AM
[EnableCors(origins: "*", headers: "*", methods: "*")]
Install-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.6