Wednesday, April 5, 2017

Enable Cors

JS cannot call Web api, it will get block, add code below to Web API web.config to enable cors.

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
  <!--<handlers>
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
   </handlers>-->
  <httpProtocol>
    <customHeaders>
      <!--<add name="Access-Control-Allow-Origin" value="*" />
       <add name="Access-Control-Allow-Headers" value="*" />
       <add name="Access-Control-Allow-Methods" value="*" />-->
      <remove name="X-Powered-By" />
    </customHeaders>
  </httpProtocol>
</system.webServer>