How to enable Cross Origin Resource Sharing in MVC

In this blog you will learn how to enable Cross Origin Resource Sharing in MVC.

There are two types how to enable CORS (Cross Origin Resource Sharing), one simply add Access-Control-Allow-Origin header value for each request that requires CORS support. Five the value of this header is “*” to grant access from any domain.

HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", "*");

Or you simply add in web.config to access in full application like this.

<system.webServer>

    <httpProtocol>

      <customHeaders>

        <clear />

        <add name="Access-Control-Allow-Origin" value="*" />

      </customHeaders>

    </httpProtocol>