我在ASP上做一个项目.NET MVC 4和我执行了以下步骤:

  1. http://blog.getbootstrap.com/2013/12/05/bootstrap-3-0-3-released/下载twitter bootstrap

  2. 将字体文件的生成操作设置为Content(文件位于~/Content/font文件夹中)

    glyphicons-halflings-regular.eot
    glyphicons-halflings-regular.svg
    glyphicons-halflings-regular.ttf
    glyphicons-halflings-regular.woff
    
  3. 添加到RouteConfig.反恐精英

    routes.IgnoreRoute("{Folder}/{*pathInfo}",new{Folder="Content"});

  4. 在Web中添加了以下元素.配置

    <?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>
    
  5. BundleConfig.cs中包含以下代码

    bundles.Add(new StyleBundle("~/bundles/maincss")
                        .Include("~/Content/bootstrap/bootstrap.css")
                        .Include("~/Content/bootstrap/bootstrap-theme.css")
                        .Include("~/Content/hbl-full.css"));
    

    还try 了以下代码

    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));
    
  6. 在Main Layout.cshtml中调用

    @风格.渲染("~/bundles/maincss")

在localhost中,图标仍然正常显示,但当我按下代码来释放服务器时,我只能看到正方形而不是图标,在Chrome的控制台选项卡中,我可以看到

获取http://domain.apphb.com/fonts/glyphicons-halflings-regular.woff 404(未找到)测试:1

获取http://domain.apphb.com/fonts/glyphicons-halflings-regular.ttf 404(未找到)测试:1

获取http://domain.apphb.com/fonts/glyphicons-halflings-regular.svg 404(未找到)测试:1

非常感谢.

推荐答案

我有这个问题,我发现它是由于在发布模式下构建时的缩小而发生的.

我没有从 bootstrap 站点手动下载文件并配置绑定,而是使用nuget软件包,它为我完成了这项工作.

如果您想这样做,请执行以下步骤.

运行以下命令以安装 bootstrap 程序:

Install-Package Twitter.Bootstrap.MVC

这将下载所有 bootstrap 程序包文件,并包括以下预定义的 bootstrap 程序包配置:

public class BootstrapBundleConfig
{
    public static void RegisterBundles()
    {
        // Add @Styles.Render("~/Content/bootstrap") in the <head/> of your _Layout.cshtml view
        // For Bootstrap theme add @Styles.Render("~/Content/bootstrap-theme") in the <head/> of your _Layout.cshtml view
        // Add @Scripts.Render("~/bundles/bootstrap") after jQuery in your _Layout.cshtml view
        // When <compilation debug="true" />, MVC4 will render the full readable version. When set to <compilation debug="false" />, the minified version will be rendered automatically
        BundleTable.Bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap.js"));
        BundleTable.Bundles.Add(new StyleBundle("~/Content/bootstrap").Include("~/Content/bootstrap.css"));
        BundleTable.Bundles.Add(new StyleBundle("~/Content/bootstrap-theme").Include("~/Content/bootstrap-theme.css"));
    }
}

上面还包括描述如何呈现包的注释.

我认为最初的404字体错误是由于Fonts文件夹与缩小的CSS中指定的级别不同.

如果您希望保留当前的解决方案,那么我修复404的唯一方法就是将字体文件夹复制到web应用程序的根目录.

要在本地进行测试,只需从web配置中删除debug="true",以保存部署到AppHarbor.

Asp.net相关问答推荐

无法从部署在应用程序负载均衡器后面的 AWS ECS 上的应用程序发送 HTTP/S 请求

C# - 将 xyz 平铺转换为纬度/经度,反之亦然,给出不同的结果

我可以将图像添加到 ASP.NET 按钮吗?

ASP MVC 授权除少数之外的所有操作

创建一个供 ASP.NET 应用程序中的所有线程使用的静态 Regex 对象是否有效?

Dotnet core 2.0 身份验证多模式身份 cookie 和 jwt

/应用程序中的服务器错误. ASP.NET

asp.net:与其中的用户控件相比,控件/页面的页面生命周期顺序是什么?

iframe.readyState 在 chrome 中不起作用

使用 C# 和 ASP.NET 从 Gmail/Hotmail/Yahoo 导入通讯簿

使用 IIS 的 ASP.NET 调试超时

对布尔查询字符串参数使用true或1

如何在新选项卡中打开 asp:HyperLink.NavigateUrl

如何以编程方式将标签的前景色设置为其默认值?

如何确定服务器端 C# 上的浏览​​器窗口大小

ASP.NET 中的全局资源与本地资源

如何从 NuGet 安装 EntityFramework 5.0(和其他旧版本)?

如何将 LINQ 左外连接限制为一行

避免将重复元素添加到列表 C#

Visual Studio 2013 ASP.NET 项目中 Antlr 包的用途是什么?