【问题标题】:Serving contain to sub domains from an MVC / IIS web application从 MVC / IIS Web 应用程序向子域提供服务
【发布时间】:2014-11-29 10:01:32
【问题描述】:

我在 tumblr 上为我的网站托管博客:

blog.withoomph.com

我已经修改了博客的主题,我想使用我自己在我们的主站点上使用的字体。我正在尝试从以下位置获取字体:

beta.withomph.com

但是,当页面尝试获取字体时,我收到了 CORS 错误。这只是最近才开始发生,因为它们过去被毫无问题地提取。

有没有一种方法可以设置 IIS 或我的 MVC 应用程序以将这些字体提供给子域?

编辑

对不起,我应该知道的比这更好。以下是更多信息:

这是获取网址的 CSS:

@font-face {
    font-family: 'avantgarde';
    src: url('http://beta.withoomph.com/content/fonts/avant_garde.eot');
    src: url('http://beta.withoomph.com/content/fonts/avant_garde.eot?#iefix') format('embedded-opentype'),
         url('http://beta.withoomph.com/content/fonts/avant_garde.woff') format('woff'),
         url('http://beta.withoomph.com/content/fonts/avant_garde.ttf') format('truetype'),
         url('http://beta.withoomph.com/content/fonts/avant_garde.svg#avantgarde_bk_btdemi') format('svg');
    font-weight: normal;
    font-style: normal;
}

这是开发控制台尝试获取字体时的错误:

来自“http://beta.withoomph.com”的字体已被阻止 通过跨域资源共享策略加载:否 请求中存在“Access-Control-Allow-Origin”标头 资源。因此不允许使用原点“http://blog.withoomph.com” 访问。

【问题讨论】:

  • 我们可以看看一些代码吗?
  • 是的,对不起,这是一个糟糕的问题,希望额外的信息能让事情更清楚。

标签: c# asp.net-mvc cors


【解决方案1】:

出于安全原因,浏览器禁止调用位于当前源之外的资源,因此您必须启用跨源资源共享。将此添加到web.config

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

欲了解更多信息,请参阅this link

【讨论】:

  • 很棒的东西,正是我想要的。非常感谢!
  • 请注意,允许* 意味着您正在接受来自任何人和所有人的请求,这可能会使您面临跨站脚本攻击。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-17
  • 1970-01-01
  • 2017-02-07
  • 2010-11-03
  • 1970-01-01
  • 1970-01-01
  • 2011-05-03
相关资源
最近更新 更多