CSS, Images, JS not loading in IIS
Solution 1:
The problem may be that IIS is not serving Static Content, which you can set up here:
Source: http://adilmughal.com/blog/2011/11/iis-7-not-loading-css-and-image/
Windows 10:
Solution 2:
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.
- I had the static content role installed
- My Web Application was in the wwwroot folder of IIS and all the Windows Folder permissions were intact (the default ones, including IIS_IUSRS)
- I added authorization for all the folders that contained the CSS, JS and images.
- 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.
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?
Solution 3:
I had a similar error, my console looked like this:
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/
).
Solution 4:
Try removing the staticContent section from your web.config.
<system.webServer>
<staticContent>
...
</staticContent>
</system.webServer>