【问题标题】:Why is Windows Azure adding '/bundles/' into all of my css image file paths?为什么 Windows Azure 将“/bundles/”添加到我的所有 css 图像文件路径中?
【发布时间】:2015-12-08 17:45:02
【问题描述】:

我正在使用 css 属性:

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

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

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

我试过了:

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

当我在网络浏览器中访问图片的 url 时,它会加载图片,所以我知道它在那里。

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

谢谢。

【问题讨论】:

  • 请检查您的应用程序中是否启用了捆绑。您要检查的文件是BundleConfig.csApp_Start 文件夹中。

标签: css azure background-image filepath


【解决方案1】:

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

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

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

消除...这个问题的最佳方法是什么?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 2017-03-05
    • 2021-07-28
    • 2018-10-14
    • 2022-11-10
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多