讓IIS靜態網站支持跨域請求

在靜態網站的web.config中配置customHeaders節點,詳情如下
<?xml version="1.0" encoding="utf-8"?>

<!--
  有關如何配置 ASP.NET 應用程序的詳細信息,請訪問
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <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>
    <staticContent>
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <remove fileExtension=".mp3" />
      <mimeMap fileExtension=".mp3" mimeType="audio/x-mpeg" />
      <remove fileExtension=".appcache" />
      <mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
    </staticContent>
        <directoryBrowse enabled="true" />
  </system.webServer>
    <location path="site.appcache">
        <system.webServer>
            <caching>
                <profiles>
                    <add extension=".appcache" policy="DontCache" kernelCachePolicy="DontCache" />
                </profiles>
            </caching>
        </system.webServer>
    </location>
</configuration>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章