CSS, Images, JS not loading in IIS

I had the same problem, an unauthenticated page would not load the CSS, JS and Images when I installed my web application in ASP.Net 4.5 in IIS 8.5 on Windows Server 2012 R2.

  1. I had the static content role installed
  2. My Web Application was in the wwwroot folder of IIS and all the Windows Folder permissions were intact (the default ones, including IIS_IUSRS)
  3. I added authorization for all the folders that contained the CSS, JS and images.
  4. I had the web application folder on a windows share, so I removed the sharing as suggested by @imran-rashid

Yet, nothing seemed to solved the problem. Then finally I tried setting the identity of the anonymous user to the App Pool Identity and it started working.

Click on the Authentication FeatureEdit the Anonymous AuthenticationChange to App Pool Identity

I banged my head for a few hours and hope that this response will save the agony for my fellow developers.

I would really like to know why this is working. Any thoughts?


I had a similar error, my console looked like this:

error

My problem was that I was running my site in a sub folder since the company was using one top domain and no sub domains. Like this:

host.com/app1

host.com/app2

My code looked like this for including scripts which worked fine on localhost but not in app1 or app2:

<link rel="stylesheet" type="text/css" href="/Content/css/font-awesome.min.css" />

Added a tilde sign ~ to src and then everything worked:

<link rel="stylesheet" type="text/css" href="~/Content/css/font-awesome.min.css" />

Explanation of ~ vs /:

  • / - Site root
  • ~/ - Root directory of the application

/ will return the root of the site (http://host.com/),

~/ will return the root of the application (http://host.com/app1/).


The problem may be that IIS is not serving Static Content, which you can set up here: enter image description here

Source: http://adilmughal.com/blog/2011/11/iis-7-not-loading-css-and-image/

Windows 10:

windows 10 version of the above dialog