Fix CORS in Firefox

CORS is a hated word anyone working on Web Solutions might have encountered if your website is accessing another website or API. So how do you ensure your website is able to the required URL ?

The first and easiest fix would be to include “Access Control” headers in your web.config.

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

That should be it for every other browser except for Firefox, particularly if you are accessing a Restful Web API. By default, Firefox assumes the Request to have “Accept” Header as “application/xml“. This can be demonstrated once your fire up your Web API in Firefox Extension RestClient.

The workaround for the problem lies in changing the “Accept” header to “application/json”.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s