本文介绍了字体在发布模式下无法正确呈现,但正在 ASP NET Webforms 中的调试模式下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 VS2013 发布时解决了字体渲染的问题.

We were able to solve the problem regarding the rendering of Fonts during release in VS2013.

app.css"和style.css"字体中的字体网址指向一个位置,例如fonts/icomoon.eot",从技术上讲,根据IIS的目录浏览无法找到具体路径.

The font urls in "app.css" and "style.css" fonts is pointing to a location for example "fonts/icomoon.eot" which technically it cannot find the specific path based on the directory browsing of the IIS.

我们通过向所有当前字体网址添加/Content/stylesheets/"来更改它,看起来像/Content/stylesheets/fonts/icomoon.eot" 它起作用了.

We changed it by adding "/Content/stylesheets/" to all of the current font urls which would look like"/Content/stylesheets/fonts/icomoon.eot" and it WORKED.

然而,我们仍然不明白为什么调试模式对我们的 css 文件的先前 url 没问题,并且字体呈现良好.

你能提出任何修复建议吗?或者我们的这个修复可以吗(手动编辑 css 文件中的 font-urls)?

Can you suggest any fix? or is this fix of ours okay (manually editing the font-urls inside the css files)?

推荐答案

我们找到了更好的字体问题解决方案.

We have found a better solution for the font issues.

asp.net 捆绑是为什么 调试发布 模式之间结果不同的根源.

The asp.net bundling was the source as to why their was a different result between debug and release mode.

默认情况下,如果编译在调试模式下,捆绑是关闭的,而如果是在发布模式下,它是打开的.

By default, if compilation is on debug mode, the bundling is turned off while if it is on release mode, it is turned on.

为了解决这个问题,我们在发布模式下关闭了 asp.net 捆绑,为此向 BundleConfig.Cs 添加了这行代码.

To fix that issue we have turned off the asp.net bundling while on release mode by adding this lines to BundleConfig.Cs.

BundleTable.EnableOptimizations = false;

asp.net 捆绑的作用是为所有 css 和 js 文件创建一个虚拟目录.问题是它无法在 css 文件中找到 url(特别是字体)的路径.

What asp.net bundling does is it creates a virtual directory for all the css and js files. The problem is that it cannot find the path of the urls (specifically the fonts) inside the css files.

但我们尝试过的另一种解决方案是:

But another solution we have tried is:

bundles.Add(new StyleBundle("~/bundles/LayoutCss").Include(
            "~/Content/stylesheets/style.css", new CssRewriteUrlTransform() )
            .Include("~/Content/stylesheets/app.css", new CssRewriteUrlTransform() )
            .Include("~/Content/bower_components/slick/dist/slick.css"));

这篇关于字体在发布模式下无法正确呈现,但正在 ASP NET Webforms 中的调试模式下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 13:47
查看更多