34

I`m working on a project in ASP.NET MVC 4 and I did following steps:

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

  2. Set Build action on font files to Content (files are located in ~/Content/font folder)

    glyphicons-halflings-regular.eot
    glyphicons-halflings-regular.svg
    glyphicons-halflings-regular.ttf
    glyphicons-halflings-regular.woff
    
  3. Added to RouteConfig.cs

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

  4. Added following elements to 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. Included following code in BundleConfig.cs

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

    Also tried with following code

    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. Called in main Layout.cshtml

    @Styles.Render("~/bundles/maincss")

Still in localhost icons are shown normally, but when I push code to release server, I can only see square instead of icon and in Chrome`s Console tab I get

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

Thank you.

22db05
  • 675
  • 1
  • 9
  • 13

7 Answers7

25

Here's how I solved it -- I'm using MVC5 and Bootstrap 3.1.1.

I have my files organized in the project like this:

/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

Then I added another level to my virtual path in the bundle config

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

Previously I had used ~/Content/css

And in the view...

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

This worked but I still got a 404 on one of the fonts... so I added Giles' solution.

<?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>
Jasen
  • 14,030
  • 3
  • 51
  • 68
  • 1
    Changing the bundle name did it for me. Thanks! – John Mc Oct 13 '14 at 09:23
  • I changes bootstrap bundle path to "~/content/bootstrap/css" and common script path to "~/content/site/css" and it works! Thanks! – Madman Jul 28 '15 at 13:29
  • I had some 404 errors and renamed my bundle from ~/Content/css to ~/Content/ccsportal and that helped as I had a css folder in the root which messed things up. However I still had some of the icons not showing up. Added a subfolder magically helped things! Thanks. – Yeronimo Sep 20 '15 at 17:56
  • This solution worked for me, although I did have to add woff2 as well. All I had to do was duplicate the "woff" lines and change "woff" to "woff2". – Aeroradish Nov 02 '15 at 15:28
23

Copying the font folder to the root of the web app and changing the mime types in web.config to

<?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>

fixed the issue for me. Please note that the .woff mimeType is different to the one in the question.

Giles Roberts
  • 6,407
  • 6
  • 48
  • 63
  • 1
    I still have the fonts in the bootstrap folder (~/Content/themes/default/libs/bootstrap/fonts) and with the extension in the web.config it now works. Thanks! – Tobias Nov 25 '14 at 15:48
9

I had the same problem, using IIS 7.5 webserver.

The solution was to add .woff to the list of file name extensions with MIME type application/octet-stream on the webserver.

You could also achieve the same in web.config:

<staticContent>
    <remove fileExtension=".woff" />
    <mimeMap fileExtension=".woff" mimeType="application/octet-stream" />
</staticContent>
Heimdalingen
  • 91
  • 1
  • 3
  • worked for me. Note: place `` inside the `` tag in the Web.Config. had to do the same for woff2 as well – GraehamF Mar 11 '15 at 23:22
7

I had this problem and I found it was happening due to the minification when building in release mode.

Rather than downloading the files manually from the bootstrap site and configuring bundling I use the nuget package which does it for me.

If you would like to do that take the following steps.

Run the following command to install Bootstrap:

Install-Package Twitter.Bootstrap.MVC

This downloads all the bootrap files and includes the below pre-defined Bootstrap bundle config:

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"));
    }
}

The above also includes comments describing how to render out the bundles.

I think the original 404 font error was due the fonts folder being at a different level to what is specified in the minified css.

If you prefer to keep your current solution the only way I could fix the 404 was to copy the font folder to the root of the web application.

To test it locally simply remove debug="true" from your web config to save deploying to AppHarbor.

hutchonoid
  • 32,982
  • 15
  • 99
  • 104
  • 1
    Eventualy I moved font folder to root. Thanks – 22db05 Jan 22 '14 at 17:00
  • Nice one. I'm surprised more people aren't having the same issue. – hutchonoid Jan 22 '14 at 17:05
  • This ended up in a right royal balls up for me. Glad I checkpointed in Git before doing this. Had to revert. It appears the Twitter.Bootstrap.MVC is a bit of a moving target and the latest version has build errors. Ended up going all the way to here http://stackoverflow.com/questions/19618771/how-to-resolve-mvc4-twitter-bootstrap-project-fail-from-simple-nuget-installatio before doing my final revert and deciding this wasn't ready for prime time. I've ended up simply amending the mimeTypes as specified in the question and copying the font folder to root then everything just worked. – Giles Roberts Mar 28 '14 at 11:28
  • Really it is just a matter of ensuring your bundle path for the StyleBundle is the same as the actual path. Thus ~/Content instead of ~/bundles – Facio Ratio Jan 14 '15 at 19:27
  • Twitter.Bootstrap.MVC is now deprecated, simply use the "boostrap" package instead. https://www.nuget.org/packages/Bootstrap – Mason240 Feb 13 '15 at 16:47
4

I had the same issue. I don't really know why but if I remove the bootstrap.min.css file and set the CssRewriteUrlTransform on the bundle everything is working. I'm using bootstrap v3.1.1

EDIT: After some investigation the solution is defined here : CssRewriteUrlTransform is not being called So removing the bootstrap.min.css or referencing bootstrap.min.css instead of bootstrap.css will force the bundling/minification on your file and so it will call the CssRewriteUrlTransform.

Community
  • 1
  • 1
asidis
  • 1,374
  • 14
  • 24
1

I had the same problem. I got around it by using bootstrap's CDN.

Gary Brunton
  • 1,840
  • 1
  • 22
  • 33
0

In the IgnoreRoute, you specified the "Content" folder. Try also adding one for fonts", since that is what your are requesting.

routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "fonts" });
Andy T
  • 10,223
  • 5
  • 53
  • 95