这是我们的网站结构
main application
sub application (index file using css is located here)
content
assets
css (CSS file located here)
images (image located here)
在css文件中,我们使用具有相对URL的免费图像,如下所示:
background: #ffffff url("../images/bodybg.png") repeat;
因此它告诉CSS在images文件夹中向上一级查找图像
这适用于我们的带有IIS的本地计算机。这被翻译为:
http://localhost/subapplication/content/assets/images/bodybg.png
但是,在我们的生产环境中,也在IIS上,它都被转换为:
https://www.oursite.com/images/bodybg.png
我尝试更改为根相对路径:
background: #ffffff url("/subapplication/content/assets/images/bodybg.png") repeat;
这解决了问题,但是没有人知道为什么相对css路径在两个环境中有两个结果吗?
似乎我们在ASP.NET MVC 5中使用捆绑的方式导致了这种情况。
在生产索引文件中,其编写方式如下:
@Styles.Render("~/Content/main")
并在bundleconfig中:
bundles
.Add(new StyleBundle("~/Content/main")
.Include("~/Content/assets/css/main.css",
转换为在代码索引文件中使用根相对路径:
/subapplication/Content/main?v=12341234lmkelmk
我需要将包渲染到实际css所在的位置,以使相对路径起作用,如下所示:
@Styles.Render("~/Content/main/assets/css/main")
bundles
.Add(new StyleBundle("~/Content/main/assets/css/main")
.Include("~/Content/assets/css/main.css",
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句