2012-12-13 10 views
5

Sitecore non supporta MVC 4 ancora e vorrei usare bundling e minification di System.Web.Optimization.Sitecore 6.6, MVC 3 e System.Web.Optimization?

Richieste fasci rispondono con 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> 

Percorsi a fasci sono virtuali e non mappano cartelle fisiche.

percorsi Ignorando getta un NotImplementedException e 500 Internal Server Error:

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

.. ma per il resto, le richieste sono gestite da Sitecore e rispondono con un 404 Not Found + Redirect.

Ho anche provato:

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

non riesco a ottenere tutto questo a lavorare insieme. Aiuto!

+0

temo che Sitecore potrebbe definire un fermo tutto percorso prima i fasci vengono gestite ... – maxbeaudoin

risposta

9

Madre di Dio!

Hackaround i seguenti itinerari:

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

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

Hai dovuto fare qualsiasi altra cosa per ottenere questo per funzionare correttamente? Ho provato ad aggiungere i percorsi, ma Sitecore mantiene dirottare le richieste del bundle o di contenuti e la restituzione di un oggetto non trovato errore. – Mike

+0

Non ho questo progetto nelle mie mani più, ma per quanto posso ricordare .. si bisogno di assicurarsi che (in alcuni.config file) che il "pattern di esclusione" è impostato su "sc_ignore_". – maxbeaudoin

+0

Ho aggiunto/content/e/bundle/a ignoreurlprefixes nel web.config. Ma sembra che tu stia dicendo che devo aggiungerne ancora di più? Andrò su Google per sc_ignore e vedrò cosa riesco a trovare. Grazie! Come nota a margine. Quando aggiungo gli URL a ignoreurlprefix, il gestore di file statici entra in gioco e ottengo solo un errore 404 regolare = \ – Mike

4

C'è un'impostazione Sitecore denominata "IgnoreUrlPrefixes", utilizzando una configurazione Sitecore includerLa possibile patchare questa impostazione per includere, ad esempio "/ bundle", che consente di utilizzare il/bundles/* urls per le funzionalità di raggruppamento di ottimizzazione Web ASP.NET.

+0

Utilizzando Sitecore 7.x questa sembra essere l'unica cosa richiesta '|/bundles' –

1

Nel mio caso, utilizzando Sitecore 6,6 aggiornamento 5, sono stato in grado di ottenere vendite abbinate a lavorare nel modo seguente:

In primo luogo, aggiungere questo al web.config:

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

In secondo luogo, ho aggiunto un metodo gasdotto per la pipeline di registrare i fasci nella tabella bundle:

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

Avanti, ho aggiunto il metodo gasdotto alla tubazione tramite un file di patch:

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

Infine, ho patchato le IgnoreUrlPrefixes impostazione in Sitecore per aggiungere il/fasci percorso

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

... Niente altro era necessario - ha funzionato come un campione.