我的网站上有一些我需要启用跨域访问的图像,但我不想将其添加到所有图像中。我知道我可以这样做:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
但有没有办法将自定义标题限制为我网站上的一个文件夹?
答案 0 :(得分:9)
是的,有。只需在该文件夹中创建一个新的web.config
文件,它将仅应用于该文件夹。
答案 1 :(得分:0)
如果您使用的是ASP身份验证,那么CORS身份验证问题可能是由ASP身份验证和重定向到您的登录页面触发的访问问题。
如果Daniel Liuzzi的答案对您不起作用,请也允许匿名访问images文件夹:
<configuration>
<!-- allow all access to the folder in question -->
<system.web>
<authorization>
<allow users="?,*" />
</authorization>
</system.web>
<!-- Daniel Liuzzi's mime header (above) for CORS access -->
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>