2012-12-13 86 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> 

...沒有別的需要 - 工作就像一個冠軍。