asp.net-mvc - Sitecore 6.6、MVC 3 和 System.Web.Optimization?

标签 asp.net-mvc sitecore bundle minify

Sitecore 尚不支持 MVC 4,我想使用 System.Web.Optimization 的 bundle 和缩小。

对 bundle 的请求会响应 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>

bundle 的路径是虚拟的,不会映射到物理文件夹。

忽略路由会引发 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>

我无法让这一切一起工作。救命!

最佳答案

上帝之母!

破解以下路线:

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

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

关于asp.net-mvc - Sitecore 6.6、MVC 3 和 System.Web.Optimization?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13867383/

相关文章:

asp.net-mvc - img src 不适用于 mvc View 中的静态图像

javascript - 是否真的有可能在雅虎的 yslow 中为动态/CMS 网站的所有内容实现等级 "A"?

ruby-on-rails - 安装 mini_racer (0.2.0) 时出错

lucene - Sitecore Lucene 索引 - 使用高级数据库爬虫找不到文件异常

workflow - sitecore 工作流权限

Magento bundle 产品仅针对 child 商品特价

Angular 4 : 'Property ' includes' is missing in type' for custom data type

c# - 使用 RouteArea 后 ASP.NET MVC 5 路由停止工作

c# - 在 C# MVC 的 Jquery 中使用 CSS 文件

c# - Url.PathAndQuery 出现错误