我的问题是,在我将网站上传到在线服务器后,除了图像、CSS和JavaScript之外,html页面显示得非常好。我确切地知道为什么会发生这种情况,这与Ogglas在这个stackoverflow问题中的回答有关:CSS、Images、JS没有在IIS 中加载
Baisically,我可以看到在谷歌调试器中显示:
<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;