2014-01-21 53 views
33

我真的在ASP.NET工作的一個項目MVC 4,我做以下步驟:Twitter的引導glyphicons不會出現在釋放模式404

  1. 下載Twitter的引導從http://blog.getbootstrap.com/2013/12/05/bootstrap-3-0-3-released/

  2. 套裝建立在字體文件的行動內容(文件位於〜/內容/字體文件夾)

    glyphicons-halflings-regular.eot 
    glyphicons-halflings-regular.svg 
    glyphicons-halflings-regular.ttf 
    glyphicons-halflings-regular.woff 
    
  3. 添加到RouteConfig.cs

    routes.IgnoreRoute(「{folder}/{* pathInfo}」,new {folder =「Content」});

  4. 添加以下元素處理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> 
    
  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")); 
    

    還與下面的代碼試圖

    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. 在主Layout.cshtml調用

    @ Styles.Render( 「〜/捆綁/ maincss」)

在本地主機圖標

不過通常示出,但是當我推代碼以釋放服務器,我只能看,而不是圖標,並在Chrome`s控制檯選項卡廣場,我得到

GET http://domain.apphb.com/fonts/glyphicons-halflings-regular.woff 404(未找到)測試:1

GET http://domain.apphb.com/fonts/glyphicons-halflings-regular.ttf 404(未找到)測試:1

GET 404(未找到)測試:1

謝謝。

+0

如若將mimeType爲WOFF文件是'< 「WOFF」 mimeMap fileExtension = mime類型= 「應​​用/字體WOFF」/>' ? –

+0

感謝您展示第4部分,這正是我需要知道在Twitter Bootstrap中使用圖標的原因。 –

回答

7

我有這個問題,我發現建立在釋放模式時,它發生是由於微小。

而不下載從bootstrap站點手動配置文件和配置捆綁我使用nuget包,它爲我做。

如果你想這樣做,採取以下步驟。

運行下面的命令來安裝引導:

Install-Package Twitter.Bootstrap.MVC 

此下載所有bootrap文件,幷包括以下預定義的引導束配置:

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字體錯誤是由於字體文件夾在縮小的CSS中指定的不同級別。

如果您更願意保留當前的解決方案,那麼我可以修復404的唯一方法就是將字體文件夾複製到Web應用程序的根目錄。

要在本地進行測試,只需從您的web配置中移除debug="true",以保存部署到AppHarbor。

+1

最終我將字體文件夾移動到了根目錄。謝謝 – 22db05

+0

不錯。我很驚訝更多的人沒有同樣的問題。 – hutchonoid

+0

這最終在一個正確的皇家球爲我。在做這件事之前,我很高興在Git中檢查了點。必須恢復。它看起來是Twitter.Bootstrap.MVC是一個移動目標,最新版本有一些錯誤。結束了一路去這裏http://stackoverflow.com/questions/19618771/how-to-resolve-mvc4-twitter-bootstrap-project-fail-from-simple-nuget-installatio在做我最後的回覆和決定之前這還沒有準備好黃金時段。我最終只是修改了問題中指定的mimeTypes,並將字體文件夾複製到root然後一切正常。 –

1

IgnoreRoute中,您指定了「Content」文件夾。嘗試還加入了一個字體」,因爲這是你的要求是什麼。

routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "fonts" }); 
+0

字體文件夾位於Content文件夾內部,它應該被現有的IgnoreRoute忽略。 – 22db05

+0

它不在我們在VS2013中創建的模板項目中,它位於根目錄中。 – Darren

1

我有同樣的問題。我通過使用bootstrap的CDN來解決它。

22

複製字體文件夾複製到Web應用程序的根目錄,在web.config中改變MIME類型來

<?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="application/font-woff" /> 
    </staticContent> 
</system.webServer> 

固定我的問題。請注意.woff mimeType與問題中的不同。

+0

這對我有效。 – Scottie

+1

我在引導文件夾(〜/ Content/themes/default/libs/bootstrap/fonts)中仍然有字體,並且在web.config中的擴展名現在可以工作。謝謝! – Tobias

+0

這工作對我來說,謝謝! – Migs

4

我有同樣的問題。我不知道爲什麼,但是如果我刪除bootstrap.min.css文件並在捆綁包上設置CssRewriteUrlTransform,那麼一切正常。我使用的引導V3.1.1

編輯: 經過一番調查後的解決方案定義如下:CssRewriteUrlTransform is not being called 因此,移除bootstrap.min.css或引用,而不是bootstrap.css將強制捆綁bootstrap.min.css/minification在你的文件,所以它會調用CssRewriteUrlTransform。

22

下面是我如何解決它 - 我使用MVC5Bootstrap 3.1.1

我安排的項目我的文件是這樣的:

/Content/Bootstrap/bootstrap.css 
        bootstrap.min.css 
/Content/fonts/glyphicons-halflings-regular.eot 
       glyphicons-halflings-regular.svg 
       glyphicons-halflings-regular.ttf 
       glyphicons-halflings-regular.woff 

然後我在束配置

bundles.Add(new StyleBundle("~/Content/site/css").Include(
    "~/Content/bootstrap/bootstrap.css", 
    "~/Content/styles/site.css" 
)); 

以前我用過~/Content/css

添加另一個層面到我的虛擬路徑

而在查看 ...

@Styles.Render("~/Content/site/css") 

這工作,但我仍然有一個字體的404 ...所以我加了Giles的解決方案。

<?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="application/font-woff" /> 
     <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" /> 
    </staticContent> 
</system.webServer> 
+0

更改軟件包名稱爲我做了。謝謝! –

+0

我將引導程序包路徑更改爲「〜/ content/bootstrap/css」,並將通用腳本路徑更改爲「〜/ content/site/css」,它的工作原理!謝謝! – Madman

+0

我有一些404錯誤,並將我的包從〜/ Content/css重命名爲〜/ Content/ccsportal,這有助於我在根目錄中創建了一個css文件夾。但是我仍然有一些圖標沒有顯示出來。添加了一個子文件夾,神奇地幫助了一切!謝謝。 – Yeronimo

9

我有同樣的問題,使用IIS 7.5 Web服務器。

解決的辦法是將.woff添加到Web服務器上MIME類型爲application/octet-stream的文件擴展名列表中。

你也可以實現web.config中的相同:

<staticContent> 
    <remove fileExtension=".woff" /> 
    <mimeMap fileExtension=".woff" mimeType="application/octet-stream" /> 
</staticContent> 
+0

爲我工作。 注意:將''放置在Web.Config的標籤中。 也必須爲woff2做同樣的事情 – GraehamF