6

SitecoreはまだMVC4をサポートしていないので、System.Web.Optimizationのバンドルとミニファイを使用したいと思います。

バンドルへのリクエストは404NotFoundで応答します。

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 Not Found+Redirectで応答します。

私も試しました:

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

これをすべて一緒に機能させることはできません。ヘルプ!

4

3 に答える 3

10

神の母!

次のルートをハックアラウンドします。

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

routes.MapRoute(
    "sc_ignore_Bundles_Js",
    "bundles/{*pathInfo}"
);
于 2012-12-13T20:24:22.567 に答える
4

「IgnoreUrlPrefixes」という名前のSitecore設定があります。sitecoreconfigincludeを使用すると、この設定にパッチを適用して、たとえば「/ bundles」を含めることができます。これにより、ASP.NETWeb最適化バンドル機能に/bundles /*URLを使用できます。

于 2013-03-29T18:15:09.360 に答える
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>

最後に、sitecoreのIgnoreUrlPrefixes設定にパッチを適用して、/bundlesパスを追加しました

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

...他に何も必要ありませんでした-チャンピオンのように働きました。

于 2013-06-13T12:55:26.800 に答える