glyphicons-halflings-regular.woff在发布模式下的内容/字体中被搜索

时间:2017-09-20 09:16:57

标签: asp.net-mvc twitter-bootstrap-3

我有一个ASP.Net MVC5应用程序,从一个示例应用程序开始。 当我部署它时,在发布模式下,我得到了

HTTP404:未找到 - 服务器未找到与请求的URI(统一资源标识符)匹配的任何内容。 GET - https://SERVER/Content/fonts/glyphicons-halflings-regular.woff2

那不是字体的位置。如果我转到https://SERVER/fonts/glyphicons-halflings-regular.woff2我可以正常下载该文件,因此它不是IIS mimeType问题。

编辑:通过删除debug =" true"可在本地重现。来自我的Web.config

我在我的应用程序中找不到任何配置,没有BundleConfig,没有,指定在哪里找到字体。如何在发布模式下解决此问题?

编辑:这是我的BundleConfig

public class BundleConfig
{
    // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/customjs").Include(
                    "~/Scripts/Custom/btn-number-{version}.js",
                    "~/Scripts/Custom/input-number-{version}.js",
                    "~/Scripts/Custom/PriceList/tax-calculation-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new ScriptBundle("~/bundles/charts").Include(
                  "~/Scripts/Chart.js"));

        // Bundle CSS for public part of the site
        bundles.Add(new StyleBundle("~/Content/Public/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));

        // Bundle CSS for dashboard and other actions, when user is logged in
        bundles.Add(new StyleBundle("~/Content/Dashboard/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css", 
                  "~/Content/dashboard.css"));
    }
}

编辑:和bootstrap.css的字体部分

@font-face {
  font-family: 'Glyphicons Halflings';

  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

2 个答案:

答案 0 :(得分:0)

这很可能是因为css文件捆绑时的相对路径会导致字体(以及css中的任何其他url内容)的无效位置。在创建包时,您需要使用CssRewriteUrlTransform来更新这些路径。

// Bundle CSS for public part of the site
bundles.Add(new StyleBundle("~/Content/Public/css")
       .Include("~/Content/bootstrap.css",
                  "~/Content/site.css", new CssRewriteUrlTransform()));

答案 1 :(得分:0)

我不明白为什么,但如果我按如下方式更新我的BundleConfig,问题就解决了。请注意,我已删除了"内容"路径的一部分,使路径不那么深。

        // Bundle CSS for public part of the site
        // Note: Don't change to deeper path, like Content/Public/css
        // This will result in broken relative paths in .css in Release mode
        bundles.Add(new StyleBundle("~/Public/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));

        // Bundle CSS for dashboard and other actions, when user is logged in
        bundles.Add(new StyleBundle("~/Dashboard/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css",
                  "~/Content/dashboard.css"));

如果有人解释为什么Debug可以处理捆绑中的额外级别而Release不能,我愿意接受他们的答案作为真正的答案。与此同时,这已经解决了问题:)