小编典典

字体真棒无法在MVC5中运行bundleconfig

css

如果我直接参考font-awesome.css_layouts页面。它会工作

<link href="~/Content/font-awesome-4.0.3/css/font-awesome.css" rel="stylesheet" />

但是我用过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

可能是什么问题呢?


阅读 470

收藏
2020-05-16

共1个答案

小编典典

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,因此绑定不会弄乱相对路径。

2020-05-16