Sitecore and ASP.net MVC
Asked Answered
T

9

36

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.

Have anybody tried this?

Is sitecore and MVC competing or Complementing technologies?

Any architectural ideas are welcome.

Tam answered 20/8, 2009 at 19:8 Comment(3)
It's worth noting to anyone that comes across this now that Sitecore will support MVC as a first-class framework in a later release. sitecore.net/Community/Business-Blogs/Technical-Trends/Posts/…Driskill
Here is a good collection of content if you are just starting out with Sitecore and MVC: sitecore-community.github.io/docs/sitecore-mvcYuzik
I have experience with Sitecore v8+, here MVC is a default option and fully supported.Maxfield
S
27

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

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

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

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

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

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

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();
        }
    }
}

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

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.

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

Best of luck.

Siret answered 3/11, 2009 at 15:29 Comment(10)
Thanks for the reply. Thats exactly what i was thinking. Do you any experiences on the sitecore module DomainObjects to build strongly-typed domain objects. I am thinking of an hybrid of domain objects containing my domain data and presentation objects which carry the data from the domain objects + multi lingual content from sitecore to the views, which present the data in different formats. The Presentation Objects are created in the controller with the help of a service layer. Let me if it makes any sense at all..Tam
Great to hear Sitecore will support MVC from version 6.4.Tam
Yes! Though nothing the pipeline abort code above is included, which is strange. btw, to belatedly answer your question, you should check out the Custom Item Generator from Velir in the Shared Source repository for making your domain objects...Siret
MVC is definitely a great fit for content driven sites. Please explain why you think it isn'tMoony
More accurate would be that URLs driven by site content and information architecture are better for content-driven sites, than standard MVC routes.Siret
MVC routes let you do anything - you could provide a greedy route at the end of your routes and map that to Sitecore content. Something like content/{*contentPath} or just {*contentPath} which will dynamically match any path in Sitecore. This way more flexible than being bound by what Sitecore lets you do.Moony
You could, and I suspect that's what Sitecore will do with their official MVC support. But until that is available, you'd have to do a lot of custom development to enable this.Siret
@techphoria414: Is there any way I could use my custom Web API with Sitecore, without having it integrated into my UI project (where the web.config, sub-layouts etc live)? In other words I'd like to have my Web API in it's own project.Club
@Club not sure, sounds like something you should post as a new question here on SOF!Siret
@techphoria414: Got it working so you can do it. You can put all the Web API logic in a separate project and just reference it from your UI project. Works perfect.Club
P
8

I think the real question you should be asking here is; if you already have Sitecore in place - why would you want the overhead and complicatino of introducing MVC?

Do you have any business requirements outside the basic web site that would necessitate MVC?

Plow answered 21/8, 2009 at 10:55 Comment(3)
Because web forms is horrible?Prospectus
How is this an answer? It's a question, at best a rhetorical one.Resistor
"Would love to hear your ideas and thoughts on this. Have anybody tried this? Is sitecore and MVC competing or Complementing technologies? Any architectural ideas are welcome."Plow
B
6

I second Mark's comment about the requirements. Is it worth the risk? You will most likely loose the following features of Sitecore if you decide not to use native rendering functionality:

  1. OMS
  2. Web Forms for Marketers
  3. Conditional Rendering
  4. Page Editor
  5. Page Designer

maybe even more.

Backset answered 31/3, 2010 at 23:12 Comment(0)
P
4

I know that Sitecore developers have considered ASP.NET MVC, but I don't know if they've tried it. I can't think of any Sitecore projects that I think would have benefited from ASP.NET MVC. The Sitecore dynamic response engine, pipelines, handlers, wildcards, and other features seem to provide a superset of what you can accomplish with MVC. Similar story with ASP.NET master pages - you could use them with Sitecore, but Sitecore's layout details are superior.

I'm not against ASP.NET MVC with or without Sitecore, but Sitecore seem to provide the features of a controller (really ASP.NET is the controller, and Sitecore just plugs in), your information architecture is the model, and your presentation components are the views.

Precedency answered 21/8, 2009 at 14:38 Comment(0)
P
3

They sure can be mixed, and I sure do see the value of it :) No native functionality is lossed with the method I describe in my blog post here: http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/

Paphlagonia answered 23/3, 2012 at 10:8 Comment(0)
O
1

As luck would have it, I'm currently working on two large projects using both technologies respectively. And while I'm big fan of both, I can't see any benefits to merging the two.

As far as Sitecore goes, there is a learning curve, but quite honestly in my case, since I actually learned ASP.NET MVC "first" as opposed to Web Forms, the learning curve has also been slightly attributed to some of my inexperience with Web Forms. That said, there still is most definitely a learning curve involved with Sitecore, but there are plenty of training and reference materials floating around to help with that. Also, the web controls that come with Sitecore make it feel a lot less like building a straight Web Forms app. Plus there's the option for using XSLT as a rendering engine which comes in handy as well.

If this is just one project you're thinking about, I would say just stick with Sitecore as it's presentation system is quite well thought out. And as Mark said above, it would really complicate things quite a bit I and I'm also not sure what there is to gain from it even. Also echoing the sentiments of commodore73, building stuff in Sitecore seriously does feel like you're using MVC already, just using a different framework.

Oruro answered 12/10, 2009 at 0:26 Comment(0)
R
0

MVC in Sitecore has potential, but isn't production ready I think. You're covering unknown ground, as I discovered when creating this blog article.

Revenuer answered 23/1, 2011 at 13:4 Comment(0)
R
0

I know this post is pretty old, but I though I would give my opinion about Sitecore MVC anyway. I've started working on a project a few months back using exclusively Sitecore MVC. There are a lot of restrictions to what I work with since this project must work with or without CMS and be able to fit in with as many CMS as possible (We currently use 2).

ASP.NET MVC was a no brainer for us. It is 2015 and we must go ahead with the new technologies. We are using Sitecore 8, and I think that Sitecore MVC has become mature with Sitecore 7.

There are still a few bumps on the road though. If you plan on using Sitecore with form posts, make sure those are made using AJAX. Doing a validation on a field can be tricky if you use regular POST actions, but there are workarounds.

Repute answered 25/6, 2015 at 23:30 Comment(0)
S
0

Now there is Habitat project.

Sitecore Habitat is a Sitecore project that is bulit using the modular architecture. In their website they present a fully working example to install and test.

Habitat project:

https://github.com/Sitecore/Habitat

Salvidor answered 16/6, 2016 at 14:59 Comment(1)
why the downvotes? this is not SPAM. That project is official from Sitecore and uses Helix for best practicesSalvidor

© 2022 - 2024 — McMap. All rights reserved.