2012-12-13 27 views
5

Sitecore không hỗ trợ MVC 4 và tôi muốn sử dụng tính năng bundling and minification của System.Web.Optimization.Sitecore 6.6, MVC 3 và System.Web.Optimization?

Yêu cầu đối với gói phản hồi 404 Không tìm thấy.

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> 

Paths để bó là ảo và không đồ đến thư mục vật lý.

tuyến Bỏ qua ném một NotImplementedException và 500 nội Server Error:

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

.. nhưng mặt khác, yêu cầu được xử lý bởi Sitecore và đáp ứng với 404 Not Found + Redirect.

Tôi cũng đã thử:

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

tôi không thể có được điều này tất cả để làm việc cùng nhau. Cứu giúp!

+0

Tôi sợ rằng Sitecore có thể xác định bắt tất cả các tuyến đường trước khi bó được xử lý ... – maxbeaudoin

Trả lời

9

Mẹ của Đức Chúa Trời!

Hackaround các tuyến đường sau:

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

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

Bạn có phải làm bất cứ điều gì khác để làm điều này hoạt động đúng không? Tôi đã thử thêm các tuyến đường nhưng sitecore tiếp tục cướp gói hoặc yêu cầu nội dung và trả về lỗi không tìm thấy mục. – Mike

+0

Tôi không có dự án này trong tay của tôi nữa nhưng theo như tôi có thể nhớ .. bạn cần phải chắc chắn (trong một số.tệp cấu hình) mà 'mẫu loại trừ' được đặt thành 'sc_ignore_'. – maxbeaudoin

+0

Tôi đã thêm/content/và/bundle/vào ignoreurlprefixes trong web.config. Nhưng có vẻ như bạn đang nói tôi cần thêm nhiều hơn nữa cho nó? Tôi sẽ google cho sc_ignore và xem những gì tôi có thể tìm thấy. Cảm ơn! Là một lưu ý phụ. Khi tôi thêm các url vào ignoreurlprefix, trình xử lý staticfile khởi động và tôi chỉ nhận được lỗi 404 thông thường = \ – Mike

4

Có một thiết lập Sitecore có tên là "IgnoreUrlPrefixes", sử dụng một cấu hình Sitecore bao gồm bạn có thể vá cài đặt này để bao gồm ví dụ như "/ bó" cho phép bạn sử dụng/bundles/* url cho các tính năng của ASP.NET Web Optimization bundling.

+0

Sử dụng Sitecore 7.x điều này có vẻ là điều duy nhất được yêu cầu '|/bundles' –

1

Trong trường hợp của tôi, sử dụng Sitecore 6.6 cập nhật 5, tôi đã có thể để có được bundling để hoạt động bằng cách làm như sau:

Đầu tiên, thêm video này vào web.config:

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

Thứ hai, tôi đã thêm một phương pháp đường ống vào đường ống để đăng ký gói trong gói bảng:

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

Tiếp theo, tôi đã thêm phương pháp đường ống vào đường ống thông qua một tập tin vá lỗ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> 

Cuối cùng, tôi vá các IgnoreUrlPrefixes thiết lập trong Sitecore để thêm/bó con đường

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

... Không có gì khác là cần thiết - làm việc như một nhà vô địch.