I am developing an ASP .Net MVC application and on my dev machine, the application runs as expected and, more importantly, the images mentioned in the CSS file are displaying correctly too.

However, when I publish this application to a testing server, the web app runs fine, but the images are not shown.

If I modify the URL in IE when testing the output from the test server, the image is returned, meaning that the file is there but it just won't appear within the view page when using the site normally.

I have tried alternative servers too, but the result is the same.

To confirm, here's a line from the CSS page referencing the image...

background-image: url('/Content/Images/Logo/myLogo.jpg');

Any suggestions?



Was it helpful?


The URLs are not correct, likely due to the fact that you are publishing in a subfolder and so they are no longer at the root of the server. I usually use Url.Content( "~/Content/Images/..." ) to build the url instead of hard-coding it. That way it will take into account the routes when building the path.


 <img src='<%= Url.Content( "~/Content/Images/banner.jpg" ) %>' alt="Banner" />


I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.

When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.

That fixed it for me, hope it works for you.

Possible relative paths are wrong...Possible that they are wrong for CSS file itself. You can use FireBug to see if CSS loaded correctly, then you can examine image request, often in such situations you will see red(error) items. This could help to localize problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top