如果我直接参考font-awesome.css_layouts页面。它会工作
font-awesome.css
<link href="~/Content/font-awesome-4.0.3/css/font-awesome.css" rel="stylesheet" />
但是我用过BundleConfig.cs。图标未显示。
BundleConfig.cs
bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/font-awesome-4.0.3/css/font-awesome.css", "~/Content/bootstrap.css", "~/Content/body.css", "~/Content/site.css", "~/Content/form.css" ));
而且我还观察到浏览器控制台对字体目录有错误。 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:51130/fonts/fontawesome- webfont.woff?v=4.0.3
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:51130/fonts/fontawesome- webfont.woff?v=4.0.3
可能是什么问题呢?
CssRewriteUrlTransform捆绑时尝试使用:
CssRewriteUrlTransform
bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.css", "~/Content/body.css", "~/Content/site.css", "~/Content/form.css" ).Include("~/Content/font-awesome-4.0.3/css/font-awesome.css", new CssRewriteUrlTransform());
这会将资产的所有url从css文件内更改为绝对url,因此绑定不会弄乱相对路径。