404 on static content (svg,woff,ttf) on Azure

asp.netasp.net MvcAzureWeb Config

asp.net Problem Overview


I am trying to add bootstrap glyphicons-halflings-regular.svg to my web site. Locally everything works fine, but on Azue I have 404 errors:

> The resource you are looking for has been removed, had its name > changed, or is temporarily unavailable.

or when I add below staticContent section to my web.config

<staticContent>
	<remove fileExtension=".woff" />
	<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
	<remove fileExtension=".ttf" />
	<mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
	<remove fileExtension=".svg" />
	<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>

I got this error:

> The controller for path > '/Content/fonts/glyphicons-halflings-regular.woff' was not found or > does not implement IController.

How should I proper configure my ASP.NET site to avoid above errors?

asp.net Solutions


Solution 1 - asp.net

I hit the same problem with .woff file. Solution with adding that extension to web.config works fine:

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

(see oryginal solution: http://www.codepal.co.uk/show/WOFF_files_return_404_in_Azure_Web_Sites)

Solution 2 - asp.net

When I put the suggested lines into web.config it didn't work. Instead I put the following lines into Web.config (note the capital letter)

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

Solution 3 - asp.net

I did not include font files in solution. This caused that publishing website does not contains this files.

Solution 4 - asp.net

If you are using the continuous deployment on Azure, verify that the "build action" of all the files that you need is Content and not None.

Solution 5 - asp.net

Have you fixed the paths in the css file that are referring to the font files? Bootstrap assumes that the css file is inside a css directory and fonts is inside a fonts-directory on the same level as the css-directory.

When you run in Azure, the site is probably running in Release-mode. This means that your css and javascript is minified and bundles. This may break your setup sometimes.

I've done the following setup when including bootstrap in my projects:

Unzip bootstrap files into the /Content directory.

Add the following lines to App_Start/BundleConfig.cs

bundles.Add(new StyleBundle("~/Content/bootstrap/css/bundle")
.Include("~/Content/bootstrap/css/bootstrap.css"));
bundles.Add(new ScriptBundle("~/Content/bootstrap/js/bundle")
.Include("~/Content/bootstrap/js/bootstrap.js"));

Add the following lines to View/Shared/_Layout.cshtml

@Styles.Render("~/Content/bootstrap/css/bundle") 
@Scripts.Render("~/Content/bootstrap/js/bundle") 

Note that jQuery must be included before the Bootstrap js-bundle.

http://hj-dev.blogspot.no/2013/02/add-twitter-bootstrap-to-mvc4.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPiotr StappView Question on Stackoverflow
Solution 1 - asp.neteldiView Answer on Stackoverflow
Solution 2 - asp.netmaracuja-juiceView Answer on Stackoverflow
Solution 3 - asp.netPiotr StappView Answer on Stackoverflow
Solution 4 - asp.netMatteo MiglioreView Answer on Stackoverflow
Solution 5 - asp.netHenningJView Answer on Stackoverflow