asp.net-mvc 如何消除找不到 glyphicons-halflings-regular.woff2 的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32300578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:29:06  来源:igfitidea点击:

How to remove error about glyphicons-halflings-regular.woff2 not found

asp.net-mvctwitter-bootstrapvisual-studioasp.net-mvc-4glyphicons

提问by Andrus

ASP.NET MVC4 Bootstrap 3 application is running from Microsoft Visual Studio Express 2013 for Web IDE.

ASP.NET MVC4 Bootstrap 3 应用程序从 Microsoft Visual Studio Express 2013 for Web IDE 运行。

Chrome console shows always error

Chrome 控制台总是显示错误

http://localhost:52216/admin/fonts/glyphicons-halflings-regular.woff2
Failed to load resource: the server responded with a status of 404 (Not Found)

This file exists in the fonts directory in the Solution Explorer. Build action is set to "Content" and Copy to Output directory is "Do not copy like in other font files". Bootstrap 3 is added to the solution using NuGet. How to fix this so that this error does not occur? Application shows Glyphicon and FontAwesome icons properly. This error always occurs at application startup.

该文件存在于解决方案资源管理器的字体目录中。构建操作设置为“内容”,复制到输出目录为“不要像其他字体文件一样复制”。使用 NuGet 将 Bootstrap 3 添加到解决方案中。如何解决此问题,以免发生此错误?应用程序正确显示 Glyphicon 和 FontAwesome 图标。此错误总是在应用程序启动时发生。

回答by TotPeRo

This problem happens because IIS does not know about woffand woff2file mime types.

发生此问题,因为IIS不知道woffwoff2文件的MIME类型。

Solution 1:

解决方案1:

Add these lines in your web.config project:

在您的 web.config 项目中添加这些行:

 <system.webServer>
  ...
  </modules>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
    </staticContent>

Solution 2:

解决方案2:

On IIS project page:

在 IIS 项目页面上:

Step 1:Go to your project IIS home page and double click on MIME Typesbutton:

第 1 步:转到您的项目 IIS 主页并双击MIME Types按钮:

Step 1

第1步

Step 2:Click on Addbutton from Actionsmenu: Step 2

第 2 步:单击菜单中的Add按钮Actions第2步

Step 3:In the middle of the screen appears a window and in this window you need to add the two lines from solution 1: Step 3

第 3 步:在屏幕中间出现一个窗口,在此窗口中您需要添加解决方案 1 中的两行: 第 3 步

回答by F.M.F.

Add this one to your html if you only have access to the html:

如果您只能访问 html,请将此添加到您的 html:

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">

回答by Stephen G Tuggy

For me, the problem was twofold: First, the version of IIS I was dealing with didn't know about the .woff2MIME type, only about .woff. I fixed that using IIS Manager at the server level, not at the web app level, so the setting wouldn't get overridden with each new app deployment. (Under IIS Manager, I went to MIME types, and added the missing .woff2, then updated .woff.)

对我来说,问题是双重的:首先,我处理的 IIS 版本不知道.woff2MIME 类型,只知道.woff. 我修复了在服务器级别使用 IIS 管理器的问题,而不是在 Web 应用程序级别,因此每个新应用程序部署都不会覆盖该设置。(在 IIS 管理器下,我转到 MIME 类型,并添加了缺失的.woff2,然后更新了.woff。)

Second, and more importantly, I was bundling bootstrap.cssalong with some other files as "~/bundles/css/site". Meanwhile, my font files were in "~/fonts". bootstrap.csslooks for the glyphicon fonts in "../fonts", which translated to "~/bundles/fonts"-- wrong path.

其次,更重要的是,我将bootstrap.css其他一些文件打包为"~/bundles/css/site". 同时,我的字体文件在"~/fonts". bootstrap.css在 中查找字形字体"../fonts",该字体转换为"~/bundles/fonts"-- 错误的路径。

In other words, my bundle path was one directory too deep. I renamed it to "~/bundles/siteCss", and updated all the references to it that I found in my project. Now bootstrap looked in "~/fonts"for the glyphicon files, which worked. Problem solved.

换句话说,我的包路径是一个太深的目录。我将它重命名为"~/bundles/siteCss",并更新了我在项目中找到的所有对它的引用。现在 bootstrap 寻找"~/fonts"glyphicon 文件,它起作用了。问题解决了。

Before I fixed the second problem above, noneof the glyphiconfont files were loading. The symptom was that all instances of glyphiconglyphs in the project just showed an empty box. However, this symptom only occurred in the deployed versions of the web app, not on my dev machine. I'm still not sure why that was the case.

在我上面固定的第二个问题,没有对的glyphicon字体文件是加载。症状是项目中的所有glyphicon字形实例都只显示一个空框。但是,此症状仅出现在已部署的 Web 应用程序版本中,而不出现在我的开发机器上。我仍然不确定为什么会这样。

回答by cirl

I tried all the suggestions above, but my actual issue was that my application was looking for the /font folder and its contents (.woff etc) in app/fonts, but my /fonts folder was on the same level as /app. I moved /fonts under /app, and it works fine now. I hope this helps someone else roaming the web for an answer.

我尝试了上述所有建议,但我的实际问题是我的应用程序正在 app/fonts 中查找 /font 文件夹及其内容(.woff 等),但我的 /fonts 文件夹与 /app 处于同一级别。我将 /fonts 移到 /app 下,现在工作正常。我希望这可以帮助其他漫游网络的人寻求答案。

回答by Diwas Poudel

This problem happens because IIS does not find the actuallocationof woff2 file mime types. Set URL of font-face properly, also keep font-family as glyphicons-halflings-regularin your CSS file as shown below.

发生此问题是因为 IIS 找不到woff2 文件 mime 类型的实际位置。正确设置 font-face 的 URL,同时在 CSS 文件中将font-family 保持为glyphicons-halflings-regular,如下所示。

@font-face {
font-family: 'glyphicons-halflings-regular'; 
src: url('../../../fonts/glyphicons-halflings-regular.woff2') format('woff2');}