【问题标题】:glyphicons-halflings-regular.woff being sought in Content/fonts in Release modeglyphicons-halflings-regular.woff 在发布模式下的内容/字体中被寻找
【发布时间】:2017-09-20 09:16:57
【问题描述】:

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

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

那不是字体所在的位置。如果我去https://SERVER/fonts/glyphicons-halflings-regular.woff2 我可以下载文件就好了,所以这不是 IIS mimeType 问题。

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

我在我的应用程序中找不到任何配置,没有 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');
}

【问题讨论】:

  • 我认为这是捆绑或 src in @font-face 的 css 的问题。从您的bootstrap.css 分享您的BundleConfig.cs 和字体部分

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


【解决方案1】:

这可能是因为当它们被捆绑时,您的 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()));

【讨论】:

  • 嗯,在哪里可以找到应用了 CSS 重写 URL 转换的文件?您需要将此参数添加到所有 CSS 包中。
  • 我做到了。我将它添加到所有 .css 包中。在 Debug 模式下,图标是可见的,而在 Release 模式下是不可见的。我束手无策,因为据我所知,当涉及到我的 BundleConfig 或脚本时,Debug 和 Release 之间没有区别......
  • 是的,但是在使用此参数应用捆绑后,CSS 期望文件在哪里? 404 错误是什么意思?
  • HTTP404: NOT FOUND - 服务器未找到与请求的 URI(统一资源标识符)匹配的任何内容。 GET - https://SERVER/Content/fonts/glyphicons-halflings-regular.woff2
  • 我找到了一个解决方案,但我不明白它为什么有效。将其发布为答案,但如果有人可以解释为什么,那么我愿意接受更准确的答案。
【解决方案2】:

我不明白为什么,但如果我如下更新我的 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 不能,我愿意接受他们的答案作为真正的答案。与此同时,这已通过问题解决:)

【讨论】:

  • Debug 只是跳过优化,因此在 Debug 模式下不执行捆绑。因此它可以在调试中工作。
猜你喜欢
  • 1970-01-01
  • 2014-04-20
  • 2015-12-14
  • 2015-07-29
  • 2014-03-29
  • 2015-10-17
  • 1970-01-01
  • 2017-12-11
  • 2016-04-08
相关资源
最近更新 更多