IIS 7.5+ Access-Control-Allow-Origin JS

Spread the love

Similar error: xmlhttprequest cannot load no ‘access-control-allow-origin’

Added in Web.config File:

<add name=“Access-Control-Allow-Origin” value=”*” />
<add name=“Access-Control-Allow-Headers” value=”Origin, X-Requested-With, Content-Type, Accept” />
<add name=“Access-Control-Allow-Methods” value=”GET, POST, PUT, DELETE, OPTIONS” />

If it don’t work, use next variant:

1. Install CORS

Open Tools>NuGet Package Manager>Package Manager Console and paste Install-Package Microsoft.AspNet.WebApi.Cors

2. Add option in config file
After installation is complete, add in Register function in file WebApiConfig.cs (App_Start/WebApiConfig.cs) next string


3. Fixed Controller
Add next string in your controller

using System.Web.Http.Cors;


[EnableCors(origins: “http://mywebclient.azurewebsites.net”, headers: “*”, methods: “*”)]

Leave a Reply