Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set access control allow origin on particular file web.config

If this were a dynamic response, I'd simply do Response.Headers.Add("Access-Control-Allow-Origin", "*"); but I have a static file I'd like to allow cross domain access to.

Is there a way to assign this header to a particular file just using web.config? Say it's just example.com/flat.json

I guess I could route the file to dynamic page, but that would be a bit silly.

like image 673
FlavorScape Avatar asked Oct 25 '12 04:10

FlavorScape


People also ask

How do I add multiple urls in Access-Control allow origin?

Sounds like the recommended way to do it is to have your server read the Origin header from the client, compare that to the list of domains you would like to allow, and if it matches, echo the value of the Origin header back to the client as the Access-Control-Allow-Origin header in the response.

Has blocked by CORS policy no Access-Control allow origin in web config?

Right click the site you want to enable CORS for and go to Properties. Change to the HTTP Headers tab. In the Custom HTTP headers section, click Add. Enter Access-Control-Allow-Origin as the header name.

How do I disable CORS in web config?

You need just need your site to send the HTTP header Access-Control-Allow-Origin with the value * to "turn off" CORs (well allow any origin).


1 Answers

This should work

<location path="Sample.txt">
    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>
like image 133
Tariqulazam Avatar answered Oct 17 '22 18:10

Tariqulazam