【问题标题】:Images displayed in Visual Studio Development Server but not IIS7图像显示在 Visual Studio 开发服务器中,但不显示在 IIS7 中
【发布时间】:2015-02-26 19:24:26
【问题描述】:

在将我的 MVC 5 项目发布到 IIS 7 时,我在让图像正常工作时遇到了一些问题。我有一个像下面这样的主体样式,它似乎通过显示白色背景而不是图像而失败(它完全跳过了灰色)

body {
background-color: grey;
background: transparent url("Images/Background.png") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
height: 100%;
}

我打开了 chrome 开发工具并查看了图像的实际链接并手动添加了“/”然后将其删除,图像显示正常,但刷新失败。除了下面定义的 404 错误外,我在控制台中没有收到任何错误。

我也尝试了以下版本(其中一些比其他版本更明显的失败)

  • Images/Background.png(无错误)
  • /Images/Background.png(404错误)
  • ~/Images/Background.png(404 错误)
  • ~Images/Background.png(404 错误)

后 3 个抛出错误如下:

- http://10.96.90.65/Images/Background.png 404 (Not Found)
 - http://10.96.90.65/SITE/Content/~/Images/Background.png 404 (Not Found)
 - http://10.96.90.65/SITE/Content/~Images/Background.png 404 (Not Found)

我适用的虚拟文件结构看起来像

  • /内容
  • /内容/图片/
  • /内容/主题/
  • /Content/*.css
  • /图片/

我正在使用 Visual Studio 2012 和 IIS 7 编辑:图片在 Internet Explorer 中加载,但不是在 Chrome 中

【问题讨论】:

  • 它“完全跳过灰色”,因为您将其设置为灰色,然后在以下行中将其设置为透明。
  • 哦。呃。接得好。但这只是次要问题。
  • 是的,我想。只是想我会提到它,因为我注意到它。 :-)

标签: css asp.net-mvc image visual-studio-2012 iis-7


【解决方案1】:

您是否尝试过使用html base tag

我之前遇到过一个问题,我无法访问 IIS 上的图像,但在本地运行时可以。我还认为有一个 IIS 设置可以更改,但当时对我来说这是不可能的,所以我从未研究过这个选项。

标题中的内容如下:

<base href="~/" />

否则,您能否告诉我们以下选项实际上试图在 IIS 服务器上查找的位置?

  • Images/Background.png(无错误)
  • /Images/Background.png(404错误)
  • ~/Images/Background.png(404 错误)
  • ~Images/Background.png(404 错误)

【讨论】:

  • 已编辑。不过,我更喜欢在 CSS 中执行此操作。我会把基本标签放在头标签中吗?
  • @brhardwick 对于列出的第一个图像路径,与文件在哪里相比,它在哪里查看?如果它与文件位置在同一个地方,那么它与我的想法无关,并且似乎是实际显示文件的问题。如果您使用开发工具并在没有错误的情况下观察连接,它是否真的找到了图像?如果它有图像作为资源,那么这是一个显示问题。
  • 第一个指向一个实际的文件。这相当令人不安。当我查看网络选项卡时,它甚至没有尝试获取文件。或者至少,它没有表明它试图得到它。
猜你喜欢
  • 2022-12-12
  • 2012-01-18
  • 1970-01-01
  • 1970-01-01
  • 2011-07-02
  • 1970-01-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多