2012-12-13 59 views
5

साइटकोर अभी तक एमवीसी 4 का समर्थन नहीं करता है और मैं System.Web.Optimization के बंडलिंग और न्यूनीकरण का उपयोग करना चाहता हूं।साइटकोर 6.6, एमवीसी 3 और सिस्टम.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

मुझे डर है कि साइटकोर को बंडलों को संभालने से पहले सभी मार्गों को पकड़ने के लिए परिभाषित किया जा सकता है ... – maxbeaudoin

उत्तर

9

भगवान की मां!

Hackaround निम्नलिखित मार्गों:

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

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

क्या आपको इसे ठीक से काम करने के लिए कुछ और करना है? मैंने मार्ग जोड़ने का प्रयास किया है, लेकिन साइटकोर बंडल या सामग्री अनुरोधों को अपहृत करता रहता है और किसी आइटम को त्रुटि नहीं देता है। – Mike

+0

मेरे पास यह प्रोजेक्ट अब मेरे हाथों में नहीं है लेकिन जहां तक ​​मुझे याद है .. आपको सुनिश्चित करना होगा (कुछ में।कॉन्फ़िगरेशन फ़ाइल) कि 'बहिष्करण पैटर्न' को 'sc_ignore_' पर सेट किया गया है। – maxbeaudoin

+0

मैंने web.config में ignoreurlprefixes को/सामग्री/और/बंडल/जोड़ा है। लेकिन ऐसा लगता है जैसे आप कह रहे हैं कि मुझे इसमें और भी जोड़ना होगा? मैं sc_ignore के लिए Google पर जाऊंगा और देख सकता हूं कि मुझे क्या मिल सकता है। धन्यवाद! एक साइड नोट के रूप में। जब मैं ignoreurlprefix में यूआरएल जोड़ता हूं, तो staticfile हैंडलर में आता है और मुझे बस नियमित 404 त्रुटि = \ – Mike

4

वहाँ एक Sitecore "IgnoreUrlPrefixes" नाम, एक sitecore config का उपयोग शामिल है यदि आप इस सेटिंग पैच उदाहरण के लिए "/ बंडलों" जो आप का उपयोग करने की अनुमति देता शामिल करने के लिए कर सकते हैं सेटिंग है/bundles/* एएसपी.NET वेब अनुकूलन बंडलिंग सुविधाओं के लिए यूआरएल।

पहले, web.config से जोड़ें::

+0

साइटकोर 7.x का उपयोग करना यह एकमात्र चीज है जो '|/बंडल' –

1

मेरे मामले में, Sitecore 6.6 का उपयोग कर अद्यतन 5, मैं निम्न कार्य करके काम करने के लिए bundling पाने के लिए कर रहा था

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

बंडल ... और कुछ नहीं की जरूरत थी - एक विजेता की तरह काम किया।