MVC捆绑 - 无法加载资源 [英] MVC Bundling - Failed to load resource

查看:151
本文介绍了MVC捆绑 - 无法加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么引起的?我与构建和本地运行就好了一个DurandalJS项目。当我尝试部署到Azure的一个网站,应用程序发布,但在浏览器与失败:

What could be causing this? I'm working with a DurandalJS project that builds and runs locally just fine. When I try to deploy to an Azure Website, the app publishes but fails in the browser with:

无法加载资源:服务器与404状态响应
  (未找到)
  <一href=\"http://appsite.azurewebsites.net/Scripts/vendor.js?v=KJCisWMhJYMzhLi_jWQXizLj9vHeNGfm_1c-uTOfBOM1\">http://appsite.azurewebsites.net/Scripts/vendor.js?v=KJCisWMhJYMzhLi_jWQXizLj9vHeNGfm_1c-uTOfBOM1

Failed to load resource: the server responded with a status of 404 (Not Found) http://appsite.azurewebsites.net/Scripts/vendor.js?v=KJCisWMhJYMzhLi_jWQXizLj9vHeNGfm_1c-uTOfBOM1

我没有任何定制的捆绑。

I haven't customized any of the bundling.

我的包CONFIGS:

my bundle configs:

public class BundleConfig
{
    // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

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

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/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 http://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));

        bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                    "~/Content/themes/base/jquery.ui.core.css",
                    "~/Content/themes/base/jquery.ui.resizable.css",
                    "~/Content/themes/base/jquery.ui.selectable.css",
                    "~/Content/themes/base/jquery.ui.accordion.css",
                    "~/Content/themes/base/jquery.ui.autocomplete.css",
                    "~/Content/themes/base/jquery.ui.button.css",
                    "~/Content/themes/base/jquery.ui.dialog.css",
                    "~/Content/themes/base/jquery.ui.slider.css",
                    "~/Content/themes/base/jquery.ui.tabs.css",
                    "~/Content/themes/base/jquery.ui.datepicker.css",
                    "~/Content/themes/base/jquery.ui.progressbar.css",
                    "~/Content/themes/base/jquery.ui.theme.css"));
    }
}

DurandalBundleConfig:

DurandalBundleConfig:

public class DurandalBundleConfig {
public static void RegisterBundles(BundleCollection bundles) {
  bundles.IgnoreList.Clear();
  AddDefaultIgnorePatterns(bundles.IgnoreList);

  bundles.Add(
    new ScriptBundle("~/Scripts/vendor.js")
        .Include("~/Scripts/jquery-{version}.js")
        .Include("~/Scripts/jquery-ui-{version}.js")
        .Include("~/Scripts/bootstrap.js")
        .Include("~/Scripts/knockout-{version}.js")
        .Include("~/Scripts/knockout.mapping-latest.js")
         .Include("~/Scripts/isotope.js")
          .Include("~/Scripts/toastr.js")
          .Include("~/Scripts/tag-it.js")
    );

  bundles.Add(
    new StyleBundle("~/Content/css")
      .Include("~/Content/ie10mobile.css")
      .Include("~/Content/app.css")
      .Include("~/Content/bootstrap.min.css")
      .Include("~/Content/bootstrap-responsive.min.css")
      .Include("~/Content/font-awesome.min.css")
      .Include("~/Content/durandal.css")
      .Include("~/Content/starterkit.css")
       .Include("~/Content/toastr.css")
       .Include("~/Content/tag-it.css")
       .Include("~/Content/zen-theme.css")
    );
}

public static void AddDefaultIgnorePatterns(IgnoreList ignoreList) {
  if(ignoreList == null) {
    throw new ArgumentNullException("ignoreList");
  }

  ignoreList.Ignore("*.intellisense.js");
  ignoreList.Ignore("*-vsdoc.js");
  ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
  //ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
  //ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
}
} 

在我的html页面我用这样的:

In my html page I use this:

@Scripts.Render("~/Scripts/vendor.js")

这是加载preventing需要的库文件(如淘汰赛)。难道是我的web.comfig的东西吗?任何提示将真棒。

This is preventing required libraries (like knockout) from loading. Could it be something in my web.comfig? Any tips would be awesome.

更新:

我可以重现本地,如果我做了以下的确切问题:

I can reproduce the exact issue locally if I do the following:

new ScriptBundle("~/Scripts/vvendor.js")  // change the virtual output directory here

我认为,这意味着该视图时,它的发表出于某种原因无法找到目录...

I think this means the view can't find the directory when it's published for some reason...

推荐答案

摆脱对ScriptBundle名​​.js文件的一部分。出于某种原因引起的问题,一个烂摊子。它应该是这样的:

Get rid of the ".js" part on the ScriptBundle name. For some reason that causes a mess of problems. It should be this:

...
new ScriptBundle("~/Scripts/vendor")
...

然后将其添加到您的网页是这样的:

Then add it to your page like this:

@Scripts.Render("~/Scripts/vendor")

这篇关于MVC捆绑 - 无法加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆