views:

897

answers:

3

Hi there,

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?

Cheers

Brett

+7  A: 

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.

Example:

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

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.

Mike Chaliy
Good plan - I'll download FireFox and FireBug and will see if that helps.
Brett Rigby
A: 

Why does this have to be done... just finishing my project and now I have to go through a change everything to this format! All my javascript is failing, all my images are failing! For some strange reason my css is just fine but why the heck isn't this more documented!? Url.Content doesn't even show up under the intellisense! ASP MVC just lost a point on my scale of love.

--very frustrated coder

Mr_E