我正在使用 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/