首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sitecore 6.6,MVC 3和System.Web.Optimization?

Sitecore 6.6,MVC 3和System.Web.Optimization?
EN

Stack Overflow用户
提问于 2012-12-13 19:52:40
回答 3查看 2.3K关注 0票数 6

Sitecore目前还不支持MVC 4,我想使用System.Web.Optimizationsbundle和小型化。

对包的请求以未找到的404响应。

BundleConfig.cs

代码语言:javascript
复制
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

代码语言:javascript
复制
@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内部服务器错误:

代码语言:javascript
复制
routes.IgnoreRoute("content/{*pathInfo}");
routes.IgnoreRoute("bundles/{*pathInfo}");

。。但是,否则,请求将由Sitecore处理,并以404 Not +重定向响应。

我也试过:

代码语言:javascript
复制
<system.webServer>
    <modules runAllManagedModulesForAllRequests="false">
        <remove name="BundleModule"/>
        <add type="System.Web.Optimization.BundleModule" name="BundleModule"/>
    </modules>

我不能让这一切一起工作。帮助!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-12-13 20:24:22

上帝之母!

绕开下列路线:

代码语言:javascript
复制
routes.MapRoute(
    "sc_ignore_Bundles_Css",
    "content/{*pathInfo}"
);

routes.MapRoute(
    "sc_ignore_Bundles_Js",
    "bundles/{*pathInfo}"
);
票数 10
EN

Stack Overflow用户

发布于 2013-03-29 18:15:09

有一个名为"IgnoreUrlPrefixes“的Sitecore设置,可以使用sitecore配置包含,您可以对该设置进行修补,以包括"/bundles”,它允许您使用/bundle/* urls来实现ASP.NET网络优化捆绑功能。

票数 4
EN

Stack Overflow用户

发布于 2013-06-13 12:55:26

在我的例子中,使用Sitecore 6.6更新5,我能够通过执行以下操作来实现捆绑:

首先,将其添加到web.config中:

代码语言:javascript
复制
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
    <remove name="BundleModule"/>
    <add type="System.Web.Optimization.BundleModule" name="BundleModule"/>
</modules>
...

其次,我向管道中添加了一个管道方法,以便在bundle表中注册这些包:

代码语言:javascript
复制
[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"));
}

接下来,我通过一个补丁文件将管道方法添加到管道中:

代码语言:javascript
复制
<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设置,以添加/bundles路径

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

..。什么都不需要--像个冠军一样工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13867383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档