Search code examples
servercorsiis-7

How to set CORS access-control-allow-origin = * on site?


I have 2 servers.

1st have a cdn domain and on that, I am running font-awesome javascript and styles. Now I want to access that scripts by using the cdn link on my other site. I tried but it shows the below error (the below URL's are examples)

Access to fetch at 'https://cdn.xyz.com/fonts/Awesome/fa-regular-400.ttf' from origin 'http://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Appreciate your answers!


Solution

  • You can follow the below steps to set Access-Control-Allow-Origin in IIS:

    1. Open Internet Information Service (IIS) Manager

    2. Select the website you require and click on HTTP Response Headers.

    3. In the Custom HTTP Response Headers, click Add

    4. Enter Access-Control-Allow-Origin as the header name, Enter * as the header value.

    5. Hit the OK button.

    6. Now, you will find the following code in your web.config file.

      <configuration>
        <system.webServer>
          <httpProtocol>
            <customHeaders>
              <add name="Access-Control-Allow-Origin" value="*" />
            </customHeaders>
          </httpProtocol>
        </system.webServer>
      </configuration>