2012-12-13 15 views
5

SitecoreはまだMVC 4をサポートしていないので、System.Web.Optimizationのバンドリングと縮小を使用したいと思います。Sitecore 6.6、MVC 3、System.Web.Optimization?

バンドルに対するリクエストは、404 Not Foundで応答します。

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}"); 

..しかし、そうでない場合、要求はサイトコアによって処理し、+リダイレクトが見つかりませんでした404で応答しています。

私も試してみた:

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

私はこのすべてが一緒に動作させることはできません。助けて!

+0

バンドルが処理される前にSitecoreがすべての経路をキャッチと定義してしまうのではないかと心配しています... – maxbeaudoin

答えて

9

GODの母!

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

web.configのignoreurlprefixesに/ content /および/ bundle /を追加しました。しかし、私はもっとそれを追加する必要があると言っているようですね?私はsc_ignoreのためにgoogleをして、私が見つけることができるものを見ます。ありがとう! 補足として。 ignoreurlprefixにURLを追加すると、staticfileハンドラが起動し、通常の404エラーが表示されます。\ – Mike

4

「IgnoreUrlPrefixes」という名前のサイトコアの設定は、サイトコアの設定を使用して、あるあなたが使用することができます。たとえば含めるには、この設定にパッチを適用することができます含める「/バンドル」/bundles/* URLには、ASP.NET Web最適化バンドル機能が含まれています。 、

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

第二:

まず、web.configファイルにこれを追加します。私の場合は

+0

Sitecore 7.xを使うと、これは唯一必要なことです。 '|/bundles' –

1

は、サイトコア6.6アップデート5を使用して、私は次のようにして動作するように束ねる取得することができましたIは、バンドル表にバンドルを登録するためにパイプラインにパイプライン方式を追加した:

[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")); 
} 

次に、Iは、パッチファイルを介してパイプラインにパイプライン方式を追加した:

<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> 

は最後に、私は/他に何も必要なかった...パス

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

をバンドルを追加するサイトコアに設定IgnoreUrlPrefixesパッチを適用 - チャンピオンのように働きました。

関連する問題