Partial routing
Extend URL routing beyond pages to route to external data or non-page content types in CMS 13.
Partial routing extends URL routing beyond pages to handle data outside Optimizely CMS or non-page content types. Register a partial router for a content type to route any remaining URL path after content routing resolves the page.
For example, http://site/News/ resolves to a page of model type NewsContainer. A partial router registered for NewsContainer routes the remaining path Sports/TheGame/ to the matching content.
IPartialRouter interface
IPartialRouter interfacePartial routers implement EPiServer.Core.Routing.IPartialRouter<TContent, TRoutedData> from the EPiServer.dll assembly. The generic constraint requires TContent : EPiServer.Core.IContent.
The interface defines the following methods:
RoutePartial– Called when content routing resolves a page of typeTContentand a remaining URL path exists. The implementation routes the remaining path.GetPartialVirtualPath– Called when the framework constructs an outgoing URL for a content instance of typeTOutgoing.
Pass RouteValues to a controller
RouteValues to a controllerPass custom data from a partial router to an MVC controller through route values or HTTP context items. UrlResolverContext.RouteValues in the RoutePartial method mirrors HttpContext.RouteValues, which is read-only in ASP.NET Core.
Add data to route values through IHttpContextAccessor.HttpContext.Items or IHttpContextAccessor.HttpContext.Request.RouteValues:
public class NewsPartialRouter: IPartialRouter<NewsContainer, NewsContent> {
private readonly IHttpContextAccessor _contextAccessor;
public object RoutePartial(NewsContainer content, UrlResolverContext urlResolverContext) {
_contextAccessor.HttpContext.Request.RouteValues.Add("paramName", paramValue);
// or
_contextAccessor.HttpContext.Items.Add("paramName", paramValue);
// MVC controller will be:
// public IActionResult Index(NewsContainer currentContent, object paramName)
}
}Updated 17 days ago
