Try our conversational search powered by Generative AI!

Custom routes are broken in 7.5

Vote:
 

In 7 I had a custom route implemented as an initialisable module which enabled me to extend the url for pages i.e.

 routes.MapContentRoute(
                name: "Search",
                url: "{node}/{action}/{searchTerm}/{page}",
                defaults: new { controller = "Search", action = "Index", searchTerm = UrlParameter.Optional, page = UrlParameter.Optional }
              
            );

This would load search pages with search term parameters e.g. 

en/search/searchAction/mySearchTerm

would be a valid url. After the upgrade to 7.5 this gives 404s. Also the upgrade had a further bug in which the start page also was 404 - e.g. localhost:17000 could no longer be hit (localhost:17000/home was fine). Removing the route fixes the bug

SO ......

My previously working custom route not only no longer works - it actually causes the start page to give 404s. 

Anyone any idea of how to fix this??

Many Thanks

 

#80026
Jan 13, 2014 17:51
Vote:
 

Could it be related to the new "strict language routing" in 7.5?

http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2013/12/Routing-changes-in-75/

#80036
Jan 14, 2014 8:40
Vote:
 

Try add a {language} segment to your route, as  "{language}/{node}/{action}/{searchTerm}/{page}"

#80042
Jan 14, 2014 9:37
Vote:
 

Thanks for the feedback. I've tried

            routes.MapContentRoute(
                name: "Search",
                url: "{language}/{node}/{action}/{searchTerm}/{page}",
                defaults: new { controller = "Search", action = "Index", searchTerm = UrlParameter.Optional, page = UrlParameter.Optional }
              );

Unfortunately the route doesn't work and the start page is broken again


#80078
Jan 14, 2014 17:07
Vote:
 

This might work:

            routes.MapEnterpriseRoutes(
                name: "Search",
                url: "{language}/{node}/{searchTerm}/{page}/{action}",
                defaults: new { controller = "Search", action = "Index", searchTerm = UrlParameter.Optional, page = UrlParameter.Optional }
);

    

#80145
Jan 15, 2014 16:50
Vote:
 

Brilliant. Thank you Per. That works

#80205
Jan 16, 2014 14:53
Vote:
 

Actually it's not the routes that have fixed it. It is the use of 

MapEnterpriseRoutes

instead of

MapContentRoute

I think i need to go back and do some reading.

Cheers

 

#80207
Jan 16, 2014 15:03
Vote:
 

It might be that the route starts to from wrong content root. If no content root is specified in MapContentRoute it will start from SiteDefinition.Current.RootPage. In your case you might want to start route from start page. If so you could use the overload to MapContentRoute that takes in a contentRootResolver delegate and pass in 

(s) => s.StartPage 

as the delegate parameter

#80209
Jan 16, 2014 15:22
Vote:
 

Just tried the above and that works too. Thanks

#80887
Feb 04, 2014 13:28
Vote:
 

Actually this is still broken. It actually hits the home controller as well as the search controller. Having the custom route runs the home controller in addition to the actually requested controller.

Anyone any ideas what might be going on?

#80985
Feb 06, 2014 13:58
Vote:
 

Actually it's the favicon causing the problem. See here for solution

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

Cheers

 

 

#80987
Feb 06, 2014 14:11
Vote:
 

Has anyone successfully gotten this to work "MapContentRoute".  Johan, i am not sure i understand passing in the (s)=>  as a delagte.  I am on 7.5 patch 10, or should I say 7.6.  If i use mapenterprise route, it works but all my 404 handling disappears and i still hit the start page. even though the page isn't found

#84880
Apr 08, 2014 18:38
Vote:
 

I did get this to work.  On the other head, is there a way to remove "Index" from the url?

         routes.MapContentRoute(
                     "SearchPage",
                     "{language}/{node}/{action}/{pageIndex}/{searchTerm}",
                     new
                     {
                         controller = "SearchPage",
                         action = "paging",
                         pageIndex = UrlParameter.Optional,
                         searchTerm = UrlParameter.Optional
                     }, (s) => s.StartPage);

    

#84887
Apr 08, 2014 21:27
Vote:
 
#87021
Edited, Jun 06, 2014 22:32
Vote:
 

Brialliant.  Thank you very much Marija.

#87023
Jun 06, 2014 23:08
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.