【问题标题】:Resources incorrectly interpreted upon loading default site加载默认站点时资源被错误解释
【发布时间】:2014-05-30 13:39:40
【问题描述】:

我在一个类中做一个 MVC ASP.NET 应用程序,在这个类中,在 Visual Studio Premium 2013 上运行的程序运行流畅,看起来像这样:

所以现在是发布的时候了,我已经完成了教授要求的所有工作。我通过 IIS 发布,默认站点如下所示:

<html>
  <head>
    <title>CTS2463</title>
  </head>
  <body>
    <p>CTS2463 CLASS</p>
    <br />
    <p>Projects:</p>
    <br />
    <ul>
      <li><a href="http:/MvcMusicStore/">MvcMusicStore</a></li>
    </ul>
    <br />
  </body>
</html>

所以项目 MvcMusicStoreC:\inetpub\wwwroot\ 下。它加载正确,我可以自己注册,“签出”订单等等。然而,它看起来像这样:

如您所见,没有资源加载。我点击了一张损坏的图片,在 Chrome 的 javascript 调试器下我得到了这个:

Resource interpreted as Stylesheet but transferred with MIME type image/svg+xml: "http://localhost/MvcMusicStore/Content/site.css". localhost/:8
Resource interpreted as Script but transferred with MIME type image/svg+xml: "http://localhost/MvcMusicStore/Scripts/modernizr-2.5.3.js". localhost/:10
Resource interpreted as Script but transferred with MIME type image/svg+xml: "http://localhost/MvcMusicStore/Scripts/jquery-1.7.1.js". localhost/:117

所以据我了解,每个资源(css、图像、js)都被转换为 xml。为什么会发生这种情况?如果您对此有解决方案,请告诉我,并提前感谢您

【问题讨论】:

    标签: javascript css asp.net-mvc iis mime


    【解决方案1】:

    尝试在 Visual Studio 上使用相对路径。对于样式,请尝试使用Styles.Render(~/Styles/stle.css),对于 JS 文件,请尝试使用 Scripts.Render(~/Scripts/script.js)

    【讨论】:

    • 我将尝试改变这一点,但它无法解释为什么它适用于课堂上的其他人。虽然每个人都通过 Windows Server 2012 R2 Hyper V 映像运行程序,但我直接在我的电脑上执行此操作,Windows 8.1
    • 原来包含您向我展示的代码的_Layout.cshtml文件已经从相关目录呈现这些资源:@Styles.Render("~/Content/css")@Scripts.Render("~/bundles/modernizr")
    • 当我自己打开一张图片时,http://localhost/MvcMusicStore/Images/placeholder.png,我得到一个页面显示:This XML file does not appear to have any style information associated with it. The document tree is shown below.
    • 你知道我做了什么吗?我去了 IIS,删除了我的项目的应用程序,再次转换它,现在它可以工作 99% ... 唯一似乎没有加载的是一个名为 logo.svg 的文件,尽管我确实有一个 logo.png在我的图片文件夹中
    猜你喜欢
    • 2019-03-03
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 2018-03-28
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多