Monday, January 19, 2015

XMLHttpRequest cannot load no 'access-control-allow-origin' header is present on the requested resource. Origin is therefore not allowed access

This error comes when a web service is request by browser (using jQuery or JavaScript). Put following httpProtocol node in system.webServer in Web.config file to resolve this issue:

  <system.webServer>
      .
      .
      .
      .
      <httpProtocol>
            <customHeaders>
                  <add name="Access-Control-Allow-Origin" value="*"/>
                  <add name="Access-Control-Allow-Headers" value="Content-Type"/>
                  <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>
            </customHeaders>
      </httpProtocol>

  </system.webServer>

No comments:

Post a Comment