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;
-
-
- 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();
- }
- }
Web.config
- <system.webServer>
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Headers" value="accept, content-type" />
- <add name="Access-Control-Allow-Origin" value="*" />
- <add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS" />
- </customHeaders>
- </httpProtocol>
- </system.webServer>