简体   繁体   English

如何在IIS7中添加具有限制的Access-Control-Allow-Origin标头

[英]How to add an Access-Control-Allow-Origin header in IIS7 with restrictions

I need to access a font file in my application from the server that I also own. 我需要从我也拥有的服务器访问我的应用程序中的字体文件。 It works for all browsers but Firefox, and I know that I need to add a 'Access-Control-Allow-Origin' header. 它适用于所有浏览器,但Firefox,我知道我需要添加一个'Access-Control-Allow-Origin'标头。

So in the root of my server there is another application with web.config to which I added: 所以在我的服务器的根目录中,我添加了另一个带有web.config的应用程序:

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
  </customHeaders>
</httpProtocol>

It works fine however, I am not sure what are the security issues here. 它工作正常,我不知道这里的安全问题是什么。 Is specifying the domain that can access it a good security resolution here? 在这里指定可以访问它的域是一个很好的安全解决方案吗? I think I'd rather have this setting only for files in font folder and not the whole application. 我想我宁愿只为font文件夹中的文件设置此设置,而不是整个应用程序。 I saw a .htaccess solution for it which requires placing the file in desired folder, but how can I do it with web.config or IIS setting? 我看到了一个.htaccess解决方案,需要将文件放在所需的文件夹中,但是如何使用web.config或IIS设置呢?

Apache: 阿帕奇:

<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "http://yourdomain.com"
</IfModule>
</FilesMatch>

Thanks a lot, 非常感谢,

Have you tried to put a web.config in the desired subfolder only? 您是否尝试过将web.config放在所需的子文件夹中? Have a look at " ASP.NET Configuration File Hierarchy and Inheritance ". 看看“ ASP.NET配置文件层次结构和继承 ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM