【问题标题】:403 Error on bundling CSS捆绑 CSS 时出现 403 错误
【发布时间】:2014-08-06 09:58:42
【问题描述】:

我的单页应用出现以下错误:

http://screencast.com/t/sEYhyowXTqxR

因此页面看起来很丑。

我的 bundleconfig.cs 我没有修改它:

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

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

            bundles.Add(
              new ScriptBundle("~/scripts/vendor")
                .Include("~/scripts/jquery-{version}.min.js")
                .Include("~/scripts/bootstrap.min.js")
              );

            bundles.Add(
             new StyleBundle("~/Content/css")
                .Include("~/Content/ie10mobile.css") // Must be first. IE10 mobile viewport fix
                .Include("~/Content/bootstrap.min.css")
                .Include("~/Content/bootstrap-responsive.min.css")
                .Include("~/Content/font-awesome.min.css")
                .Include("~/Content/styles.css")
             );
        }

还有我的 VS:(我觉得一切都很好)

http://screencast.com/t/TQFAPCEsV

更新:

当我在 web.config 上将调试模式更改为 false 时发生这种情况,当调试模式为 true 时,网页呈现正常并且网络选项卡上没有显示错误

【问题讨论】:

  • 你在 global.asax 文件中注册了 bundle 吗???
  • 是的,上面写着:BundleConfig.RegisterBundles(BundleTable.Bundles);

标签: asp.net asp.net-mvc bundling-and-minification


【解决方案1】:

试试这个

捆绑和缩小仅在 debug=false 时发生

http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

确保您已在 Global.asax. 中注册捆绑包

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

        }

确保您拥有所有必需的 dll 引用。

System.Web.Optimization.dll

WebGrease.dll

Antlr3.Runtime.dll

所有的css文件都应该在指定的有效文件夹中。

更新

确保包的虚拟路径(StyleBundle 构造函数的参数)与文件系统中的文件夹不匹配

【讨论】:

  • 我有所有 3 个 dll,在 global.asax 中我有这个:BundleConfig.RegisterBundles(BundleTable.Bundles);
  • 确保 bundle 的虚拟路径(StyleBundle 构造函数的参数)与文件系统中的文件夹不匹配。
  • 那是问题谢谢,字体真棒 nuget 包在名为 css 的内容下创建一个文件夹。
猜你喜欢
  • 2013-08-30
  • 2013-11-15
  • 1970-01-01
  • 2013-08-23
  • 2017-07-11
  • 2021-05-25
  • 1970-01-01
  • 1970-01-01
  • 2013-06-16
相关资源
最近更新 更多