Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

MapContentRoute and routing Issues

Vote:
 

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,
                };

                routes.MapContentRoute(
                    "PaginationRoute",
                    "{language}/{node}/{action}/{pageIndex}",
                        new
                        {
                            controller = "NewListingPageController",
                            action = "paging",
                            pageIndex = UrlParameter.Optional
                        }, parameters);
            }

            base.RegisterRoutes(routes);
            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.

#86723
May 29, 2014 3:52
Vote:
 

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.

#86751
May 29, 2014 15:37
Vote:
 

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 127.0.0.1 meaning ContentReference.StartPage will only be set if you have a site with '*' defined in host mapping.

#86785
May 30, 2014 16:01
Vote:
 

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

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=86459

#86792
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.