Skip to main content

Font Awesome and MVC 4 bundle

I have a MVC 4 web project and I used FontAwesome in my code. It works perfect in development environment, but the FontAwesome icon does not show up in production environment.

I used style bundling:

            bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css", "~/Content/menu.css", "~/Content/font-awesome-4.0.3/css/font-awesome.css"));

Using Fiddler tool, I can see the HTTP GET for the style bundle is:

GET /Content/css?v=1fdJNYlrmyYR2zfWNxGwp9byu_Xm_F8yrFMQHaWibnk1 HTTP/1.1

As you can see, the virtual path for the bundled style is under /Content

In my site, I have this following folder structure in /Content





Open "font-awesome.css" file, at the beginning of the file, you can see the font-face definition:
 


 The relative path here assume the style sheet is loaded from "/Content/font-awsome-4.0.3/css", so the "../fonts" will point to "/Content/font-awesome-4.0.3/fonts" folder. However, in case of style bundling, the virtual path where the style sheet is loaded has changed to "/Content". Therefore, the FontAwesome can not find the desired font file.

In order to make it work, I changed the url part "../fonts/" to "./font-awesome-4.0.3/fonts/". After that, everything works as expected.

Note: you need to change both font-awesome.css and font-awesome.min.css files. The latter is actually the one used in release mode.

Conclusion:
The virtual path in style bundle and script bundle has important meaning. It changes the path the style or script files are actually loaded. Therefore, you have to pay much attention to it. It may break your application in production environment.

Comments

Popular posts from this blog

Manage IIS 7 remotely using PowerShell and AppCmd

We can use  Windows PowerShell remoting features  to manage IIS 7 websites remotely.  Currently, remoting is supported on Windows Vista with Service Pack 1 or later, Windows 7, Windows Server 2008, and Windows Server 2008 Release 2.  Start Windows PowerShell as an administrator by right-clicking the Windows PowerShell shortcut and selecting Run As Administrator .  Enable PowerShell Remoting with Enable-PSRemoting -Force Starting a Remote Session using:  Enter-PSSession -ComputerName <COMPUTER> -Credential <USER> Now the PowerShell connected to the remote server. Any commands issued with work against the remote server. We can use the Appcmd.exe command line tool to manage remote server just as what we do locally. For example, to add an application pool: c:\windows\system32\inetsrv\appcmd add apppool /name:"Contoso" /managedPipelineMode:Integrated /managedRuntimeVersion:"v4.0" /enable32BitAppOnWin64:true To change application pool for a

Entity framework code first error: OriginalValues cannot be used for entities in the Added state

When I was using Entity framework code first, I encountered an error when I tried to create an entity into database. The entity is: [ Table (" EmployeeProfile ")]     public partial class EmployeeProfile     {         [ Key ]         [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]         public int EmployeeProfileID { get; set; }         [ ForeignKey ("Employee")]         public int EmployeeID { get; set; }         public virtual Employee Employee { get; set; }         [ ForeignKey (" Profile ")]         public int ProfileID { get; set; }         public virtual Profile Profile { get; set; }         [ Required ]         [ StringLength (255)]         public string ProfileValue { get; set; }     } When creating the entity, some entities have the ProfileValue="", this causes the EntityValidationException with the detailed message " OriginalValues cannot be used for entities in the Added state ". I want to allow the Prof

X509Certificate2: The system cannot find the file specified.

When I use the new X509Certificate2(fileName, password, X509KeyStorageFlags.DefaultKeySet) to create certificate from certificate file containing private key in my web application, I got following error message: System . Security . Cryptography . CryptographicException : The system cannot find the file specified . at System . Security . Cryptography . CryptographicException . ThrowCryptogaphicException ( Int32 hr ) at System . Security . Cryptography . X509Certificates . X509Utils . _LoadCertFromBlob ( Byte [] rawData , IntPtr password , UInt32 dwFlags , Boolean persistKeySet , SafeCertContextHandle & pCertCtx ) at System . Security . Cryptography . X509Certificates . X509Certificate . LoadCertificateFromBlob ( Byte [] rawData , Object password , X509KeyStorageFlags keyStorageFlags ) at System . Security . Cryptography . X509Certificates . X509Certificate2 .. ctor ( Byte [] rawData , String password , X509KeyStorageFlags keyStorageFlags ) In orde