由 IIS 提供服务时,Fontawesome 不起作用 [英] Fontawesome does not work when served by IIS

查看:40
本文介绍了由 IIS 提供服务时,Fontawesome 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将应用程序放在 IIS7 服务器上时,FontAwesome 对我不起作用.

FontAwesome does not work for me when I put my app on IIS7 server.

在 Firefox 中,请求的 URL 被编码为 http://l2etest.kema.intra/fonts/fontawesome-webfont.ttf%3Fv=4.0.3 我得到 404.当我更改 %3F? 一切正常.

In Firefox the requested URL is encoded to http://l2etest.kema.intra/fonts/fontawesome-webfont.ttf%3Fv=4.0.3 and I get 404. When I change %3F to ? everything works fine.

同样的事情发生在 IE 中,但请求转到 eot 字体.

Same thing happens in IE, but the request goes to eot font.

这是我在 CSS 中的内容(与 FontAwesome 页面相同):

This is what I have in CSS (same as on FontAwesome page):

@font-face {
  font-family: 'FontAwesome';
  src: url('../fonts/fontawesome-webfont.eot?');
  src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.0.3') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff?v=4.0.3') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.0.3') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.0.3#fontawesomeregular') format('svg');
  font-weight: normal;
  font-style: normal;
}

我认为问题在于 IIS 对 URL 进行编码,而不是请求 ../fonts/fontawesome-webfont.eot? 请求转到 ../fonts/fontawesome-webfont.eot%3F.

I think the problem is that IIS encodes the URLs and instead of requesting ../fonts/fontawesome-webfont.eot? the request goes to ../fonts/fontawesome-webfont.eot%3F.

请不要建议删除?"或 URL 中的#".它们是故意存在的,而且是必不可少的.问题是如何使 IIS 不以这种方式对 URL 进行编码.任何线索将不胜感激.

Please do not suggest removing '?' or '#' from the URLs. They are there on purpose and are essential. The question is how to make IIS not to encode the URLs in that way. Any clues will be appreciated.

编辑:顺便提一句.当我在 web.config 中设置 requestValidationMode 和 requestPathInvalidCharacters 时会发生上述情况:

Edit: Btw. the above situation takes place when in web.config I set requestValidationMode and requestPathInvalidCharacters:

<httpRuntime shutdownTimeout="360" maxRequestLength="102400" enable="true" requestValidationMode="2.0" requestPathInvalidCharacters="" />

没有它我得到 400(错误请求):从客户端检测到有潜在危险的 Request.Path 值 (?)

Without it I get 400 (Bad request): A potentially dangerous Request.Path value was detected from the client (?)

如何修复 IIS 以正确提供字体?

How can I fix IIS to serve the font properly?

编辑2:好的,我找到了问题的原因.MVC3 的 SquishIt 捆绑工具正在更改这些字符.当我从包中排除 font-awesome.css 时,一切正常.

推荐答案

用于 MVC3 的 SquishIt 捆绑工具是对字体路径进行 url 编码,所以 ../fonts/fontawesome-webfont.eot? 在css 文件已更改为 ../fonts/fontawesome-webfont.eot%3F.这通常返回 400,因为 %3F 被认为是不安全的.如果设置 requestPathInvalidCharacters="" 则 %3F 被认为是安全的,但显然没有文件 ``../fonts/fontawesome-webfont.eot%3F`,因此是 404.

SquishIt bundling tool for MVC3 was url-encoding the font paths, so ../fonts/fontawesome-webfont.eot? in css file was changed to ../fonts/fontawesome-webfont.eot%3F. This normally returns 400, because %3F is considered unsafe. If you set requestPathInvalidCharacters="" then %3F is considered safe, but there is obviously no file ``../fonts/fontawesome-webfont.eot%3F`, therefore 404.

我从包中删除了 fontawesome.css,一切正常.

I removed fontawesome.css from the bundle and everything works fine.

这篇关于由 IIS 提供服务时,Fontawesome 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆