我有一个.NET MVC项目。我管理bundleconfig文件中的所有.css和.js文件。
它在本地调试模式下工作得很好。但是当我运行这个项目发布模式时,
使所有的javascript文件与bundle类似;
<script src="/bundles/alljquery?v=UzNlCXfliUxnARi00NzVdOS0lml6av0Kte2hPdkLmLw1"></script>
我在国内看到了这条线,但它不起作用。例如,我在一个不起作用的函数中编写了一个警报。
我在包中找了一个JavaScript行,找到了它。所以它实际上加载了文件。但我没有看到警觉或其他行动。
这是我的registerBundles方法;
public static void RegisterBundles(BundleCollection bundles)
{
#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif
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/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/Sitecss").IncludeDirectory("~/Content/css", "*.css",true));
bundles.Add(new ScriptBundle("~/bundles/alljquery").IncludeDirectory("~/Content/js", "*.js", true));
var jsFiles = Directory.GetFiles(HttpContext.Current.Server.MapPath("/Content/Pages"), "*.js");
foreach (var jsFile in jsFiles)
{
var bundleName = Path.GetFileNameWithoutExtension(jsFile);
bundles.Add(new ScriptBundle("~/bundles/jsMrT/" + bundleName).Include(
"~/Content/pages/" + Path.GetFileName(jsFile)));
}
}
我试试这个;
BundleTable.EnableOptimizations = true;
我试试这个;
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
</system.webServer>
我该怎么解决呢?
谢谢。