I have implemented a custom route "/performer/{performer-name}"
that I have mapped to a CMS page with actual url "/performers/performer".
I have followed the guides available for Umbraco 8 and have implemented a RegisterCustomRouteComposer logic to be able to register my route.
The issue I have is that top navigation razor logic fails on the page in question with the following:
[ArgumentException: Value cannot be null or whitespace. Parameter name: text] Umbraco.Web.Routing.UrlInfo..ctor(String text, Boolean isUrl, String culture) +153 Umbraco.Web.Routing.CustomRouteUrlProvider.GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlProviderMode mode, String culture, Uri current)
This is thrown in the topNavigation partial, the Url property of PublishedContentWrapped:
<a class="nav-link" href="@item.Url">@item.Name</a> // item is IPublishedContent
Weirdly, this only becomes an issue after an app pool / website recycle. Rebuilding the solution with a trivial change fixes it..
Custom Route Composer:
public class RegisterCustomRouteComposer : ComponentComposer<RegisterCustomRouteComponent>
{
}
public class RegisterCustomRouteComponent : IComponent
{
public void Initialize()
{
RegisterRoutes(RouteTable.Routes);
}
public void Terminate()
{
}
private static void RegisterRoutes(RouteCollection routes)
{
RouteTable.Routes.MapUmbracoRoute("Performer details", "performer/{performername}", new
{
controller = "Performer",
action = "Index",
performername = UrlParameter.Optional
}, new PerformerNodeRouteHandler());
}
}
Virtual Route Handler:
public class PerformerNodeRouteHandler : UmbracoVirtualNodeRouteHandler
{
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
{
var performerPage = umbracoContext.ContentCache.GetAtRoot().First().Descendant<Performer>();
return performerPage;
}
}
Controller:
public class PerformerController : Umbraco.Web.Mvc.RenderMvcController
{
// GET: Performer page
public ActionResult Index(ContentModel model, string performername)
{
var viewModel = new PerformerViewModel(model.Content){PerformerName = performername };
return CurrentTemplate(viewModel);
}
}
Also noticed that in the controller index action above, the "model.Content.Url" (ContentModel type argument) also throws the same error when debugging.
Custom routes - IPublishedContent Url error
Hi guys,
I have implemented a custom route "/performer/{performer-name}" that I have mapped to a CMS page with actual url "/performers/performer". I have followed the guides available for Umbraco 8 and have implemented a RegisterCustomRouteComposer logic to be able to register my route.
The issue I have is that top navigation razor logic fails on the page in question with the following:
This is thrown in the topNavigation partial, the Url property of PublishedContentWrapped:
Weirdly, this only becomes an issue after an app pool / website recycle. Rebuilding the solution with a trivial change fixes it..
Custom Route Composer:
Virtual Route Handler:
Controller:
Any help on this would be much appreciated!
Thanks, Ross
Also noticed that in the controller index action above, the "model.Content.Url" (ContentModel type argument) also throws the same error when debugging.
Hi Ross,
Not Sure if this Works. Just remove the Blank Space and replace it with "-" hyphen in the {performername} .
RouteTable.Routes.MapUmbracoRoute("Performer details", "performer/{performername(in this field space need to be replace with hyphen )}", new
Thanks,
Shekhar
is working on a reply...