css - 为什么 Windows Azure 将 '/bundles/' 添加到我的所有 css 图像文件路径中?

标签 css azure background-image filepath

我正在使用 css 属性:

background-image: url(/Content/Images/background.jpg);

但是,当部署到 Windows Azure 时,它​​会出现文件未找到错误,因为它试图从以下位置检索图像:

...azurewebsites.net/bundles/Content/Images/background.jpg

我已经尝试过:

'~/', '../', 'Content/', '/Content' & even the full path.

当我简单地在网络浏览器中访问图像的 URL 时,它会加载该图像,因此我知道它在那里。

消除或解决此问题的最佳方法是什么?

谢谢。

最佳答案

Why is Windows Azure adding '/bundles/' into all of my css image file paths?

您的 CSS 文件正在获取 bundled 。 ASP.NET 正在将您的 CSS 文件放入一个新文件中并将其存储在 mydomain.net/bundles/somefile.css 。网络浏览器正在寻找您的图像相对于 CSS 文件位置

这仅发生在 Azure 上,因为捆绑仅在发布配置中运行,而不是在调试配置中运行。因此,您可以通过设置 <compilation debug="false" /> 在本地测试捆绑。在您的 web.config 文件中。

What is the best way to remove ... this problem?

看看这个:MVC4 StyleBundle not resolving images还有这个MVC cannot display image using background-url in css - uses bundling ,或者只是不使用捆绑。 :)

关于css - 为什么 Windows Azure 将 '/bundles/' 添加到我的所有 css 图像文件路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535744/

相关文章:

Azure DevOps 仪表板 Markdown 小部件 - 添加自定义图像

css - 内联 UL 尺寸调整/定位有问题

css - "less"过滤器问题

特定行的 Jquery div 选择器

Azure 虚拟机 CPU 核心限制

azure - Application Insights 中缺少故障异常智能警报

ios - 如何从 UINavigationBar 中删除背景图像

css - 如何根据一侧的背景图像添加三 Angular 形边框(垂直)?

html - 如何以这种方式布局html CSS?

html - 让第一个和最后一个 child 占据剩余的水平空间