My all applications were working fine but suddenly all sites under IIS are not loading css, images, scripts. It redirect to login page.
If i login it works fine. e.g. mysite.com/Account/LogOn?ReturnUrl=%2fpublic%2fimages%2ficons%2f41.png
On my local machine it works fine without login.
This question is related to
c#
asp.net-mvc
iis
If you're seeing 403 errors in your browser console, check your MVC Bundle Config. Bundle names should not match any existing folder names in your project.
eg.
bundles.Add(new StyleBundle("~/Content/css")...
...would cause issues for IIS if the folder structure $(ProjectDir)\Content\css exists in your project, since it tries to look within the existing folder for bundle content that's not there.
Instead just use something like:
bundles.Add(new StyleBundle("~/Content/cssbundle")...
If you tried all the above solutions and still have problems, consider using the method ResolveClientUrl() of ASP.NET .
A script for Example :
Instead of using
<script src="~/dist/js/app.min.js" ></script>
Use the method
<script src="<%= ResolveClientUrl("~/dist/js/app.min.js") %>" ></script>
This was my solution that worked for a friend I was helping!
I added app.UseStaticFiles();
this code in starup.cs of Configure method, than it is fixed.
And Check your permission on this folder.
I had this same problem. For me, it was due to Cache-Control header being set at the server level in IIS to no-cache, no-store. So for my application I had to add in the below to my web.config:
<httpProtocol>
<customHeaders>
<remove name="Cache-Control" />
</customHeaders>
</httpProtocol>
To fix this:
Go to Internet Information Service (IIS)
Click on your website you are trying to load image on
Under IIS section, Open the Authentication menu and Enable Windows Authentication as well.
This is an authentication issue. In my case, it solved by below steps: 1- Go to IIS manager, in the left pane, expand the server root and select your web application from Sites node. 2- In the Home screen, go to IIS section and select Authentication. 3- Enable Anonymous Authentication. 4- Then, select Edit and set Edit Anonymous Authentication Credentials to Application pool identity.
Add this to your web.config
<location path="Images">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
My hour of pain was due to defining MIME types in the web.config. I needed this for the development server but local IIS hated it because it duplicated MIME types... once I removed these from the web.config the problem with js, css, and images not loading went away.
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:
One possible cause of this is that your application expects to run on port 443 (standard SSL port) and port 443 is already in use. I have run into this several times with developers trying to run our application while Skype is running on their computers.
Incredibly, Skype runs on port 443. This is a horrible design flaw in my opinion. If you see your application trying to run on 444 instead of 443, shut down Skype and the problem will go away.
Try removing the staticContent section from your web.config.
<system.webServer>
<staticContent>
...
</staticContent>
</system.webServer>
You probably have Windows authentication enabled in your web.config. On a local machine, your Windows credentials are automatically passed and it works. On a live site, you are treated as an anonymous user (IE setting can control this, but don't modify this unless you really know what you are doing).
This causes the following:
This isn't broken, just working as intended, but to "fix" this:
In my case when none of my javascript, png, or css files were getting loaded I tried most of the answers above and none seemed to do the trick.
I finally found "Request Filters", and actually had to add .js, .png, .css as an enabled/accepted file type.
Once I made this change, all files were being served properly.
Use this in configuration section of your web.config file:
<location path="images">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="css">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="js">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
One suggestion I have found helpful in the past when developing sites in localhost test environment when working with a copy of production site. Make sure that you comment out the canonical tags:
<!--<base href="http://www.example.com/">//-->
This issue occurs when IIS does not render the static contents like your JS, CSS, Image files.
To resolve this issue, you need to follow the below steps:
GO to Control Panel > Turn Windows features on or off > Internet Information Services > World Wide Web Services > Common HTTP Features > Static Content.
Ensure that static content is turned on.
Bingo. And you are done. Hard-reload the page and you will be able to see all the static contents.
This might not answer your question but I've been banging my head with the same symptoms with a new IIS installation. CSS, JS and images were not showing up. Was due to the "Static Content" role not being installed in IIS 7.5.
I had exact same problem, tried all of the suggestions but got nothing. Bugged me hours. Turned out my ISP blocked port 80 for some reasons.
Advice: check your traffic. Make sure port 80 works both locally (i.e. firewall) and externally.
For Images use
@Url.Content("~/assets/bg4.jpg")
on a Style use this
style="background-image:url(@Url.Content("~/assets/bg4.jpg"))
For me adding this in the web.config
resolved the problem
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule"/>
</modules>
</system.webServer>
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.
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?
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/
).
Source: Stackoverflow.com