Sitecore的和ASP.net MVC [英] Sitecore and ASP.net MVC

查看:575
本文介绍了Sitecore的和ASP.net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经开始了与Sitecore的为我们的CMS的新项目。我想用Sitecore的作为内容创作工具,并使用ASP.net MVC作为内容交付(CDA),方用Sitecore的沿。很想听听您对此的意见和想法。

We are starting off a new project with sitecore as our CMS. I was thinking of using Sitecore as the Content Authoring Tool and use ASP.net MVC as in the Content delivery(CDA) Side along with Sitecore. Would love to hear your ideas and thoughts on this.

有任何人试过这种?

Sitecore的是和MVC竞争性或补充技术?

Is sitecore and MVC competing or Complementing technologies?

任何建筑理念是值得欢迎的。

Any architectural ideas are welcome.

推荐答案

有关某些情况下,可以有巨​​大的好处,以合并这两个。 MVC是不是一个伟大的适合内容驱动的网站。然而,具有结构化流和多个数据presentations web应用从它非常受益。 Sitecore的有几分限制的,当涉及到数据的多个presentations - 你只能在一个项目定义一组的设计细节。如果你没有为所见即所得的编辑或轻松一点击preVIEW要求,你可以使用Sitecore的作为数据存储库,并利用一些来自其管道(如语言)背景下的价值优势。

For certain cases, there can be huge benefit to merging the two. MVC isn't that great of a fit for content-driven sites. However, web applications with structured flow and multiple presentations of data benefit hugely from it. Sitecore has somewhat of a limitation when it comes to multiple presentations of data -- you can only define one set of design details on an item. If you don't have requirements for WYSIWYG editing or easy one-click preview, you can use Sitecore as a data repository, and take advantage of some of the Context values that come from its pipeline (such as language).

一对夫妇的修改是必要的Sitecore的HTTP管道,使这项工作:

A couple modifications are necessary to the Sitecore HTTP pipeline to make this work:

1)如果使用IIS6的ASPX扩展获得ASP.NET来处理请求的MVC(如/Controller.aspx/Action),修复Sitecore的文件路径解析(没有在Sitecore的如何解决,这将导致文件路径的错误道路越来越切碎)。

1) If using the aspx extension in IIS6 to get ASP.NET to handle MVC requests (e.g. /Controller.aspx/Action), fix Sitecore's FilePath parsing (there is a bug in how Sitecore resolves the FilePath that will result in the path getting chopped).

要解决这个问题,将新的处理器在HTT prequestBegin管道的开始。

To fix this, place a new processor at the start of the httpRequestBegin pipeline.

public class MvcFixHttpProcessor : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
    public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
    {
        //when using a path such as /Controller.aspx/Blahblahblah, Sitecore's parsing of FilePath can break if Blahblahblah is too long
        RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(args.Context));
        if (routeData != null)
        {
            args.Url.FilePath = args.Context.Request.Url.LocalPath;
        }
    }
}

(编辑2011年9月13日:我还没有使用上述修复程序一段时间)

(Edit 9/13/2011: I haven't had to use the above fix in some time.)

2)告诉Sitecore的忽略被路由到ASP.NET MVC

2) Tell Sitecore to ignore URLs that are routed to ASP.NET MVC

要做到这一点,将在HTT prequestBegin管道继ItemResolver一个新的处理器。

To accomplish this, place a new processor in the httpRequestBegin pipeline following the ItemResolver.

public class SystemWebRoutingResolver : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
    public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
    {
        RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(args.Context));
        if (routeData != null)
        {
            args.AbortPipeline();
        }
    }
}

如果使用您的Sitecore的网址,语言,你将需要添加结合Sitecore的链接产生与MVC ActionLink的一代一些自定义逻辑,以确保语言添加到您的MVC URL的开始。然而,随着上述管道的修改,增加语言的网址应该对MVC路由无副作用(因为Sitecore的读语言重写后的URL)。

If using languages in your Sitecore URLs, you will need to add some custom logic that combines Sitecore link generation with MVC ActionLink generation, to ensure that language is added to the start of your MVC URL. However with the pipeline modifications above, the addition of language to the URL should have no side effects on MVC routing (because Sitecore rewrites the URL after reading the language).

再一次,这种方法只适用于某些类型的应用是有用的。不过在这种情况下,Sitecore的使得你的模型一个优秀的数据层。考虑创建自定义项目包装,以创建一个基于Sitecore的项目强类型的域对象。

Once again, this approach is only useful for certain types of applications. In those cases though, Sitecore makes an excellent data layer for your model. Look into creating custom Item wrappers to create strongly-typed domain objects based on Sitecore Items.

(编辑2011年9月13日:自定义项发生器这个伟大工程<一个。 href=\"http://blog.velir.com/index.php/2010/10/19/custom-item-generator/\">http://blog.velir.com/index.php/2010/10/19/custom-item-generator/)

(Edit 9/13/2011: Custom Item Generator works great for this. http://blog.velir.com/index.php/2010/10/19/custom-item-generator/)

好运。

这篇关于Sitecore的和ASP.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆