Below code sample which i have implemented.
Global.asax
- protected void Application_BeginRequest(object sender, EventArgs e)
- {
- var context = HttpContext.Current;
- var response = context.Response;
- // enable CORS
- response.AddHeader("Access-Control-Allow-Origin", "*");
- if (context.Request.HttpMethod == "OPTIONS")
- {
- response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
- response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
- response.End();
- }
- }
-
-
-
"Access-Control-Allow-Headers" value="accept, content-type" /> -
"Access-Control-Allow-Origin" value="*" /> -
"Access-Control-Allow-Methods" value="POST, GET, OPTIONS" />

Arun RamPosted Aug 5, 2019, 4:06 AM
Manas MohapatraPosted May 21, 2017, 4:28 AM
Nilesh JadavPosted May 20, 2017, 8:59 PM
Try these links, it is having nice doucmentation on enabling cors in asp.net web api: