Search code examples
asp.net-mvcasp.net-mvc-4sitecoresitecore7sitecore-mvc

Sitecore multisite MVC solution


I'm new to Sitecore MVC and currently with web forms I have all the sites organized under:

\Website\Sites\Site1\css|js|Layouts|Sublayouts|etc.
\Website\Sites\Site{n}\css|js|Layouts|Sublayouts|etc.

I'm able to add an MVC site to my solution and works fine alongside the web forms sites; however, adding a second MVC site that happen to have the same controller/view names generates a conflict.

For example, if I create a controller for Site1

Controllers/Site1/FooController (has index and hello)

Then the views are:

Views/Foo/Index
Views/Foo/Hello

But if Site2 also has a controller with the same name then it's a conflict:

Controllers/Site2/FooController (has index and hello)

Then the views are:

Views/Foo/Index
Views/Foo/Hello

But they're used by Site1.

The question is how to setup two (or more) MVC sites that happen to have the same controller/view names. Is there a recommended way to structure the sites in the solution or do I have to override pipelines/processors?

Thanks

Update:

Thanks everyone. Areas solved my problem but introduced two new problems:

  1. The conflict in the controller names which solved by putting the namespace, class and dll names in the controller name in Sitecore - reference: http://blog.xcentium.com/2014/03/sitecore-mvc-and-duplicate-controller-names/

  2. When the controller returns a view, I have to put the full path of the view; otherwise, I get an error where the view is not found. For example: return View("~/Areas/Site1/Views/Home/Index.cshtml");

I'm looking into a fix provided from a developer from Sitecore's forum: http://www.chrisvandesteeg.nl/2014/06/13/sitecore-mvc-in-a-multisite-environment-areas/

I'll try it out and report back.


Solution

  • you need to use namespaces in routes.MapRoute, look at the below posts which have already discussed:

    Is it possible, in MVC3, to have the same controller name in different areas?

    Multiple MVC projects in a single solution

    and below is the post by John west post which relates your situation:

    http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2012/06/Using-Web-Forms-and-MVC-in-a-Single-Solution-with-the-Sitecore-ASPNET-CMS.aspx