我正在ASP.NET MVC 4项目中工作,并完成了以下步骤:
从http://blog.getbootstrap.com/2013/12/05/bootstrap-3-0-3-released/下载了Twitter Bootstrap。
将字体文件的构建操作设置为Content(文件位于~/Content/font文件夹中)。
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
添加到 RouteConfig.cs
routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Content" });
将以下元素添加到 Web.config
<?xml version="1.0" encoding="UTF-8"?>
<system.webServer>
<staticContent>
<remove fileExtension=".eot" />
<remove fileExtension=".ttf" />
<remove fileExtension=".otf"/>
<remove fileExtension=".woff"/>
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".ttf" mimeType="font/ttf" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
</staticContent>
</system.webServer>
将以下代码添加到BundleConfig.cs中:
bundles.Add(new StyleBundle("~/bundles/maincss")
.Include("~/Content/bootstrap/bootstrap.css")
.Include("~/Content/bootstrap/bootstrap-theme.css")
.Include("~/Content/hbl-full.css"));
也尝试使用以下代码
IItemTransform cssFixer = new CssRewriteUrlTransform();
bundles.Add(new StyleBundle("~/bundles/maincss")
.Include("~/Content/bootstrap/bootstrap.css", cssFixer)
.Include("~/Content/bootstrap/bootstrap-theme.css", cssFixer)
.Include("~/Content/hbl-full.css", cssFixer));
在主要的Layout.cshtml中调用
@Styles.Render("~/bundles/maincss")
在本地主机上图标显示正常,但当我将代码推送到发布服务器时,我只能看到方块而不是图标,并且在Chrome的“控制台”选项卡中会出现以下内容:
GET http://domain.apphb.com/fonts/glyphicons-halflings-regular.woff 404 (Not Found) test:1
GET http://domain.apphb.com/fonts/glyphicons-halflings-regular.ttf 404 (Not Found) test:1
GET http://domain.apphb.com/fonts/glyphicons-halflings-regular.svg 404 (Not Found) test:1
谢谢。
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
吗? - Giles Roberts