使用MVC瓦特/捆绑当CSS无效相对路径 [英] Relative paths in CSS not valid when using MVC w/Bundles

查看:204
本文介绍了使用MVC瓦特/捆绑当CSS无效相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了数个月MVC5 Web应用程序。我已经发布到每一个用于开发,测试和预期的公共服务器3台服务器。一切都已经由一个团队十几beta测试者的测试,并决定做出现场与Web应用程序在本周末。

I've been developing a MVC5 web application for several months. I've published to each of 3 servers used for development, testing and the intended public server. Everything has been tested by a team of a dozen beta testers and a decision was made to go live with the web app this weekend.

此前发布的Web应用程序,以现场(公共)主机我修改了web.config中禁用调试模式的公共站点。发布后,各种问题随之而来,与缺少CSS和JS资源。

Prior to publishing the web app to the live (public) host I modified the web.config to disable debug mode for the public site. After publishing, all kinds of problems cropped up related to missing CSS and JS resources.

阅读了大量关于包和404错误的文章后,我发现一个暗示以下内容添加到Web.config文件:

After reading a lot of articles regarding Bundles and 404 errors, I found one that hinted to add the following to Web.config:

<modules runAllManagedModulesForAllRequests="true">
  <remove name="BundleModule" />
  <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>

这解决了StyleBundle和ScriptBundle配置的404的问题,但现在我已经为$ P $ 404的图像错误pviously工作的罚款。我不知道的最好的方式来解决这些。我不想重新定位图像和我不想要编辑的CSS,因为这些都是发行文件(jQueryUI的,的ThemeRoller,数据表等)。我要离开他们分发文件夹结构和原始的源文件(CSS和JS)不变。

This resolved the 404 issues for the StyleBundle and ScriptBundle configurations, but now I have 404 errors for images that previously worked fine. I'm not sure of the best way to resolve these. I don't want to relocate the images and I don't want to edit the CSS since these are distribution files (jQueryUI, ThemeRoller, DataTables, etc). I want to leave their distribution folder structure and original source files (CSS and JS) unmodified.

问题的一个例子

数据表分布是我的〜/脚本文件夹:

DataTables distribution is in my ~/Scripts folder:

/Scripts/DataTables-1.10.2/
/Scripts/DataTables-1.10.2/media/css
/Scripts/DataTables-1.10.2/media/images
/Scripts/DataTables-1.10.2/media/js

捆绑配置:

bundles.Add(new ScriptBundle("~/bundles/DataTables").Include(
     "~/Scripts/DataTables-1.10.2/media/js/jquery.dataTables.js"));

bundles.Add(new StyleBundle("~/bundles/DataTables.css").Include(
     "~/Scripts/DataTables-1.10.2/media/css/jquery.dataTables.css"));

jquery.dataTables.css包含引用../images/someimage.png和Web.config中调试模式下启用这个完美的作品。现在,调试模式已被禁用,并捆绑在与缩小/组合,我得到404错误:

jquery.dataTables.css contains references to ../images/someimage.png and with Web.config debug mode enabled this works flawlessly. Now that debug mode has been disabled and Bundles are minifying/combining, I am getting 404 errors:

http://example.com/GenericError.htm?aspxerrorpath=/images/someimage.png"

这好像图像URL现在假设是相对于/捆绑/ - 虽然我不肯定的。

It seems as though the image URL is now assumed to be relative to /Bundles/ - though I'm not positive.

必须有一个额外的配置我失踪。有人能指出我朝着正确的方向吗?

There must be an additional configuration I'm missing. Can someone point me in the right direction?

修改

拉​​斐尔在这个问题上的意见和他的URL到另一个类似的问题,SO无助于解决这一问题。 BundleTransformer的肖恩的建议似乎像它可能工作,但我没有找到有关如何安装该软件包的任何文档。

Raphael's comments on this question and his URL to another similar SO question did not help to resolve this problem. Sean's recommendation of BundleTransformer seems like it might work but I don't find any documentation on how to install this package.

推荐答案

请参阅我的答案在:
<一href=\"https://stackoverflow.com/questions/24823259/css-js-bundle-in-single-file-in-mvc-when-publish-with-release-option/24823976#24823976\">CSS/JS捆绑在MVC单个文件时发布选项

它处理这个​​确切的问题,你有选项来解决这个问题。

It deals with this exact issue and the options you have to resolve it.

这篇关于使用MVC瓦特/捆绑当CSS无效相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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