CORS settings for IIS 7.5

廉价感情. 提交于 2019-11-28 08:40:56
Zehra Subaş

If you are asking this to solve CORS problem, you can follow this solution below.

NOTE: Before adding all this you should consider security issues.

  1. Add this to your web.config file:

    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
          <add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD, OPTIONS" />
          <add name="Access-Control-Allow-Credentials" value="true"/>
          <add name="Access-Control-Allow-Headers" value="X-Requested-With, origin, content-type, accept" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
    
  2. If you have Content-type parameter in your ajax call or you are doing PUT request.Those are considered as PreFlight requests.Preflight requests are doing OPTION request before sending main request(PUT,DELETE etc).You can add below method to your global.asax file to pass successfully OPTION process:

    protected void Application_BeginRequest()
    {
        if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
        {
            Response.Flush();
        }
    }
    

To have more information about Preflight requests you can check here

For solution number 2 you can have detailed information from here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!