2012-12-13 36 views
5

Sitecore还不支持MVC 4,我想使用System.Web.Optimization的捆绑和缩小。Sitecore 6.6,MVC 3和System.Web.Optimization?

请求捆绑响应404未找到。

BundleConfig.cs

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", 
        "~/Content/960.gs/960.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")); 
    } 
} 

_Layout.cshtml

@using System.Web.Optimization 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8" /> 
     <title>@ViewBag.Title</title> 
     @Styles.Render("~/Content/css") 
     @Scripts.Render("~/bundles/modernizr") 
    </head> 
    <body> 
     <div class="container_12"> 
      <a href="/"><h1>Title</h1></a> 
      @Html.Action("Utilities", "Navigation") 
      @Html.Action("Menu", "Navigation") 
      @RenderBody() 
     </div> 
     @Scripts.Render("~/bundles/jquery") 
     @RenderSection("scripts", required: false) 
    </body> 
</html> 

路径到束是虚拟的,并且不映射到物理文件夹。

忽略路线抛出一个NotImplementedException和500内部服务器错误:

routes.IgnoreRoute("content/{*pathInfo}"); 
routes.IgnoreRoute("bundles/{*pathInfo}"); 

..但除此之外,请求由Sitecore的处理,并与404未找到+重定向响应。

我也试过:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="false"> 
     <remove name="BundleModule"/> 
     <add type="System.Web.Optimization.BundleModule" name="BundleModule"/> 
    </modules> 

我不能让这一切一起工作。帮帮我!

+0

我担心Sitecore可能会在绑定处理之前定义一条所有路径...... – maxbeaudoin

回答

9

上帝的母亲!

Hackaround以下途径:

routes.MapRoute(
    "sc_ignore_Bundles_Css", 
    "content/{*pathInfo}" 
); 

routes.MapRoute(
    "sc_ignore_Bundles_Js", 
    "bundles/{*pathInfo}" 
); 
+0

您是否必须执行其他任何操作才能使其正常工作? 我试过添加路线,但sitecore一直劫持捆绑或内容请求并返回一个找不到的项目错误。 – Mike

+0

我不再有这个项目在我的手中,但据我记得..你需要确保(在一些。配置文件)将'排除模式'设置为'sc_ignore_'。 – maxbeaudoin

+0

我已将/ content /和/ bundle /添加到web.config中的ignoreurlprefixes中。但是这听起来像是在说我需要为它增加更多内容?我会为sc_ignore谷歌,看看我能找到什么。谢谢! 作为一个方面说明。当我将urls添加到ignoreurlprefix时,静态文件处理程序开始运行,并且我刚刚得到一个常规的404错误= \ – Mike

4

有一个名为“IgnoreUrlPrefixes”,使用Sitecore的配置包括可以修补此设置包括例如“/捆”,它允许使用一个Sitecore的设置/ bundles/* url为ASP.NET Web优化捆绑功能。

+0

使用Sitecore 7.x这似乎是唯一需要'|/bundles' –

1

在我的情况下,使用Sitecore的6.6更新5,我能得到捆绑做的工作如下:

首先,这种添加到Web.config:

<system.webServer> 
<modules runAllManagedModulesForAllRequests="false"> 
    <remove name="BundleModule"/> 
    <add type="System.Web.Optimization.BundleModule" name="BundleModule"/> 
</modules> 
... 

其次,我添加了一个管道方法到流水线登记在包表束:

[UsedImplicitly] 
public virtual void Process(PipelineArgs args) 
{ 
    BundleTable.EnableOptimizations = true;    
    RegisterBundles(BundleTable.Bundles); 
} 

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

接下来,我通过贴剂文件添加流水线方法将管道:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
     <pipelines> 
     <initialize> 
      <processor patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc']" 
       type="MyStuff.Web.Pipelines.RegisterMyBundles, MyStuff.Web" /> 
     </initialize> 
     </pipelines> 
    </sitecore> 
</configuration> 

最后,我修补了IgnoreUrlPrefixes在Sitecore的设置,添加/捆绑路径

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
     <settings> 
     <setting name="IgnoreUrlPrefixes" 
        value="(all other sitecore paths here)|/bundles"/> 
     </settings> 
    </sitecore> 
</configuration> 

...没有别的需要 - 工作就像一个冠军。