【问题标题】:Failed to load resource, error 404, running with IIS Local加载资源失败,错误 404,使用 IIS Local 运行
【发布时间】:2017-06-06 13:21:17
【问题描述】:

早上好,我开发了一个 mvc 5 应用程序,在开发过程中我使用了 IIS Express,那里的所有文件都完美加载,当我上传到我的 IIS Local (7) 仍然在我的机器上进行测试时,我意识到有几个文件是未加载。

Failed to load resource: the server responded with a status of 404 (Not Found)
glyphicons-halflings-regular.woff

检查时我发现文件没有加载,因为实际上尝试执行 GET 的路径不正确。它试图上路:

http://localhost/content/fonts/glyphicons-halflings-regular.woff

但正确的文件应该是:

http://localhost/aprovacoes/content/fonts/glyphicons-halflings-regular.woff

在获取中,项目名称丢失,因此未加载。

为了解决这个特定来源的问题,我需要编辑 bootstrap.min.css 文件并从 url 更改 url:

url(/content/fonts/glyphicons-halflings-regular.woff)

url(aprovacoes/content/fonts/glyphicons-halflings-regular.woff)

但是在每个项目中都没有加载几个文件,为了解决我正在逐个文件编辑 css 文件,难道没有另一种方法可以在所有 css 文件中映射这个正确的路径吗?

非常感谢您

【问题讨论】:

  • 在 url 中需要项目名称对我来说似乎很奇怪,但这取决于您的 iis 设置以及项目的设置和发布方式。如果您可以添加有关可能有用的设置的信息。

标签: c# asp.net asp.net-mvc iis-7


【解决方案1】:

使用资源相对路径。例如,如果您的文件结构如下:

+ bootstrap.css
- fonts
    + glyphicons-halflings-regular.woff

然后,使用 URL:fonts/glyphicons-halflings-regular.woff。或者如果是这样的:

- css
    + bootstrap.css
- fonts
    + glyphicons-halflings-regular.woff

然后,您将使用:../fonts/glyphicons-halflings-regular.woff

这样,只要文件之间的相对路径保持一致,站点的部署方式和位置都无关紧要。

【讨论】:

  • 在某些文件中确实运行良好,但是在 css 中已经加载的某些 url 中,我不得不手动更改,无论如何,我能够更轻松地进行调整,谢谢。
猜你喜欢
  • 1970-01-01
  • 2013-10-19
  • 2019-07-16
  • 2019-02-26
  • 2014-04-08
  • 1970-01-01
  • 1970-01-01
  • 2019-12-16
  • 2020-03-15
相关资源
最近更新 更多