Invalid path for MVC website images in release version

when starting my mvc website locally (VS IIS) the images are displayed correctly:

css snippet:

.sprites { background: transparent url(../images/sprites.png) no-repeat 0 0; } 

However, when the site is published to a server or local IIS (not VS IIS), the images do not load (indicating the wrong path)

the only way to correctly display images on the server is to change the css files, and instead of "../images/sprites.png" there is "/content/images/sprites.png"

why?

+4
source share
3 answers

I understood:

MVC4 comes with the file \App_Start\BundleConfig.cs , which is used to minimize css / js scripts.

Whenever I published my site (RELEASE), it would call \ Content \ css (a minimized file) that contained the paths to my images ("../images/etc .."), which was incorrect because css the file was no longer WITHIN / Content / Styles / style.css, but / Content / css (minimized version).

I had to change it:

From:

 bundles.Add(new StyleBundle("~/Content/css").Include(            "~/Content/styles/all.css",  .. 

To:

  bundles.Add(new StyleBundle("~/Content/styles/css").Include( "~/Content/styles/all.css", 

..

and in my layout.cshtml:

 @Styles.Render("~/Content/styles/css") 
+5
source

It seems that the path in your CSS does not indicate the correct location of the image. .. points one level up, I assume that there is no folder with images in the directory, so you must explicitly specify the contents / images folder.

0
source

The css path should be the same relative to the image path on both systems. This is true?

0
source

All Articles