javascript - ASP.NET MVC 5 网站中的 CSS 和 Javascript 以及图像在部署后不会显示

标签 javascript html css asp.net asp.net-mvc-5

我的问题是,在我将我的网站上传到在线服务器后,除了图像、CSS 和 JavaScript 之外,html 页面显示完全正常。我确切地知道为什么会发生这种情况,并且它与这个 stackoverflow 问题中的 Ogglas 回答有关:CSS, Images, JS not loading in IIS

基本上,我可以看到在 Google 调试器中显示:

<link href="/Content/css?v=oJetwWdJWV96VzkmdyDS6ZG-GSKbNSyRhMkB7__C1dQ1" rel="stylesheet">

<script src="/bundles/modernizr?v=wBEWDufH_8Md-Pbioxomt90vm6tJN2Pyy9u9zHtWsPo1"></script>

但是在/Content/bundles 之前应该有一个~ 所以链接应该是

<link href="~/Content/css?v=oJetwWdJWV96VzkmdyDS6ZG-GSKbNSyRhMkB7__C1dQ1" rel="stylesheet">

<script src="~/bundles/modernizr?v=wBEWDufH_8Md-Pbioxomt90vm6tJN2Pyy9u9zHtWsPo1"></script>

因为~符号表示应用程序的根目录。

问题是我不知道如何在我的 ASP.NET MVC 5 应用程序中纠正这个问题。

我的 bundleConfig.cs 文件看起来像这样:

 public static void RegisterBundles(BundleCollection bundles)
    {


        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/toastr.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                   "~/Content/toastr.css",
                  "~/Content/site.css"));
    }
}

所以我不明白应该在哪里进行此修改,以便在部署我的网站后,我的样式链接包含 ~ 符号。

最佳答案

在你的包配置中试试这个

 BundleTable.EnableOptimizations = false;

关于javascript - ASP.NET MVC 5 网站中的 CSS 和 Javascript 以及图像在部署后不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51305970/

相关文章:

javascript - 如何使用javascript更改html中元素的顺序

javascript - 使用 JavaScript 在 div 中添加/删除 HTML

javascript - 如何将公共(public)属性添加到所有对象的属性(速记)

html - 图片下的链接无法点击

html - 网站图标未显示在 Google Chrome 中

html - 使用 Java API 将 .html 文件转换为 .mhtml

javascript - 如何将模型字段传递给 View 中的 Javascript 函数?

javascript - React : Paginated table vs Scrollable table for column sort 中的速度比较

javascript - 使用网格显示时如何正确定位 css post 元素

javascript - 防止双重提交并允许 "required"字段