JS 和 CSS 没有被加载。文件似乎是空的

JS and CSS are not being loaded. Files seems to be empty

我正在使用 ASP.NET MVC,我的应用程序托管在本地 IIS 中。一切正常。但是,当我的一位同事从 TFS 服务器下载了该项目的副本并尝试对其进行设置时,事情开始变得奇怪起来。 CSS 未加载 JS。

当我通过页面源代码浏览到这些链接时,我得到的是空文件。好像文件是空的,其实不是。

   <link href="/Content/bootstrap.css" rel="stylesheet"/>
   <script src="/Scripts/modernizr-2.6.2.js"></script>

这是我的包配置。

    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));
               .Include("~/Content/bootstrap.css")
              // ...
    );

SO 中的许多答案都建议通过 web.config 禁用调试,但我需要调试。

编辑: 这一定与 IIS 配置有关,因为我从本地 IIS 更改为 ISS Express 并且一切正常。

要启用捆绑和缩小,请将调试值设置为 "false"。您可以使用 BundleTable class.

上的 EnableOptimizations 属性 覆盖 Web.config 设置
<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

除非 EnableOptimizations 为真或 Web.config 文件中编译元素中的调试属性设置为假,否则文件不会被捆绑或缩小。此外,将不使用文件的 .min 版本,将选择完整的调试版本。

public static void RegisterBundles(BundleCollection bundles)
{
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));
               .Include("~/Content/bootstrap.css");

       BundleTable.EnableOptimizations = true;
}

作为临时解决方案,我将 Local IIS 更改为 ISS Express,一切都按预期加载。

更新:我通过在 IIS 中启用静态内容找到了解决方案。