如何在IIS发布后修复CSS中的图像路径? [英] How to fix images paths in CSS after IIS publishing?

查看:207
本文介绍了如何在IIS发布后修复CSS中的图像路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC(V4)的新手,我将网站发布到IIS后出现问题。
通过Web浏览器(和页面检查器)在IIS express中查看时,我的网站运行正常。但是,当我将我的网站(通过VS2012)发布到IIS时,我的CSS中的所有图像都被破坏了。

I'm new with MVC (V4) and I have an issue after publishing my site to IIS. My site works perfectly when viewed in IIS express though the web browser (and page inspector). However, when I publish my website (through VS2012) to IIS all my Images being references from my CSSs are broken.

我的CSS文件夹如下:

My CSS folder is as follows:

ROOT\Content\MyCss

我的图片文件夹是:

ROOT\Images\MyImages

IIS虚拟目录和项目目录中的文件夹结构相同。

我的所有图片都是这样引用的:

All my images are referenced like this:

../../Images/MyImages/image.jpg

当我将CSS引用更改为 ../ Images / MyImages / image.jpg 它再次开始工作。
这不包括IIS应用程序/虚拟目录的实际物理文件夹路径。

When I change my CSS references to ../Images/MyImages/image.jpg it starts to work again. This does not consists to the actual physical folder paths of the IIS application/Virtual directory.

我将不胜感激任何帮助解决这个问题。

I will appreciate any help solving this out.

推荐答案

如果您正在使用捆绑包,则应使用〜/ eg。 @ Styles.Render(〜/ bundles / stylebundle)在您的视图中。

If you are using bundles you should use ~/ eg. @Styles.Render("~/bundles/stylebundle") in your views.

定义捆绑包时用〜/启动文件路径。例如

When defining your bundles always start the file paths with ~/. eg

bundles.Add(new StyleBundle(〜/ bundles / test)
.Include(〜/ content / test /test.css));

css中的任何路径都应该相对于css文件本身。

Any paths in your css should be relative to the css file itself.

例如 background-image:url('../../ Images / test.jpg');

我刚刚使用与你所拥有的相同的结构构建了一个测试站点并坚持我上面所写的内容,它都可以在调试和发布中使用。要在您的本地计算机上伪装捆绑配置文件,请添加

I've just built a test site using the same structure you have and sticking to what I've written above and it all works in both debug and release. To fake the release mode on your local machine inyour bundle config file add

BundleTable.EnableOptimizations = true;

这篇关于如何在IIS发布后修复CSS中的图像路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆