Case Study:
It is very important
to separate CMS and CD level MVC routing . When we deploy CD content delivery
for any web then it should have very specific routing for the web and most of
the cms specific routing should be entrusted to cms solution. It is simple you
move all the cms level custom route to custom library and later reference and
allow to run at runtime using config patch specific to environment. Like
SiteSetting.CMS.Config vs SiteSetting.CD.Config this is will part of continous
deployment where it will be picked up during depployment to specific cms and CD
environment. By doing this we are separating the responsibility and it help
maitain consistent approach specific to cms and cd. This also good for
performance of application and it will not conlict with web solution specific
to its functionality.
CD with specific to
web page
Say http://abc.com/homepage which internally
call api via ajax -xhr request say http://abc.com/abc/api/home/Get
CMS with specific to
admin or shell page
http://abc.cms/sitecore/admin/api/user
this is very specific to cms
Now when you are
employing this solution in MVC ensure it is separated for each of this
environment. The cms web server will have routing logic loaded at runtime
specific to its env without adding extra overload to web CD environment.
Ref:
Implementation Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.Diagnostics; | |
using Sitecore.Pipelines; | |
using System.Web.Mvc; | |
using System.Web.Routing; | |
namespace Abc.Platform.Pipelines.Mvc | |
{ | |
public class RegisterCustomRoutes | |
{ | |
public void Process(PipelineArgs args) | |
{ | |
Log.Info("Sitecore is starting", this); | |
RegisterRoutes(RouteTable.Routes); | |
} | |
public void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
routes.MapRoute( | |
"admin controller", | |
"sitecore/admin/abc/{controller}/{action}", | |
new { controller = "user", action = "index", id = UrlParameter.Optional } | |
); | |
routes.MapRoute( | |
"admin api", | |
"sitecore/admin/abc/api/{controller}/{action}", | |
new { controller = "admin", action = "deleteLogin", id = UrlParameter.Optional } | |
); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- For more information on using transformations | |
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. --> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> | |
<sitecore> | |
<pipelines> | |
<initialize> | |
<processor type="Abc.Platform.Pipelines.Mvc.RegisterCustomRoutes, Abc.Platform" patch:after="processor[@type='Sitecore.Pipelines.Loader.ShowVersion, Sitecore.Kernel']" xdt:Transform="Insert"/> | |
</initialize> | |
</pipelines> | |
</sitecore> | |
</configuration> |