Try our conversational search powered by Generative AI!

MapContentRoute and routing Issues


I am really strugging to add a new url route to the routes collection.  I have the following code.

protected override void RegisterRoutes(RouteCollection routes)
            if (!ContentReference.IsNullOrEmpty(ContentReference.StartPage))
                IUrlSegmentRouter instance = ServiceLocator.Current.GetInstance<IUrlSegmentRouter>();
                instance.RootResolver = (s) => s.StartPage;
                MapContentRouteParameters parameters = new MapContentRouteParameters
                    UrlSegmentRouter = instance,
                    BasePathResolver = new Func<RequestContext, RouteValueDictionary, string>(EPiServer.Web.Routing.RouteCollectionExtensions.ResolveBasePath),
                    Direction = SupportedDirection.Incoming,

                            controller = "NewListingPageController",
                            action = "paging",
                            pageIndex = UrlParameter.Optional
                        }, parameters);

            routes.MapRoute("default", "{controller}/{action}", new { action = "index" });

This always results in a 404.  I have the following action as well.

public ActionResult Paging(NewsListingPage currentPage, int pageIndex = 1)
            var model = new NewsListingViewModel<NewsListingPage, NewsArticlePage>(currentPage);

            var filteredPages = GetNewsItems(currentPage.ContentLink);
            model.TotalItems = filteredPages.Count();
            model.PageIndex = pageIndex;
            model.PageWeight = currentPage.PageWeight;
            model.Pages = filteredPages.Skip((pageIndex - 1) * model.PageWeight).Take(model.PageWeight);

            return View("Index", model);

Why is this never hit.  I have tried almost everything to get this workig and I cannot figure it out.  WHAT AM I MISSING.

Thanks in advance.

May 29, 2014 3:52

I noticed I have the name controller in the controller as the name of the controller but even if i take out Controller so it is just controller="NewListingPage"  it still fails.  I tried changing the direction to "SuppoprtedDirection.Both" and that fails to do anything but throw a 404 as well.

May 29, 2014 15:37

Have you tried to remove the line

if (!ContentReference.IsNullOrEmpty(ContentReference.StartPage))

your code doesn't seem to be dependent on StartPage anyway. The request from IIS when RegisterRoutes is called is typically called with host meaning ContentReference.StartPage will only be set if you have a site with '*' defined in host mapping.

May 30, 2014 16:01

Maybe it's because of the sea bug that I have, read more here;

May 30, 2014 21:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.