Custom Routing Kentico 12 MVC

Armend Sejdiu asked on June 6, 2019 15:18

To make the editors happy and the website more SEO friendly also regarding multilanguage I need to implement custom urls or routing. For example to be able to use the Page Alias/Node Alias as a part of the url like this: https://mydomain/{Page Alias}.


I just tried this article https://devnet.kentico.com/articles/routing-and-url-handling-in-mvc but without sucess.

I tried to use this part to insert to the routing table but did not work:

routes.MapRoute(
"Culture based",
"{cultureCode}/{nodeAlias}",
new { controller = "Content", action = "Index" });

Correct Answer

Trevor Fayas answered on June 6, 2019 21:16

Recent Answers


Roman Hutnyk answered on June 6, 2019 15:26

What's wrong with it? What is the result you're getting?

0 votesVote for this answer Mark as a Correct answer

Armend Sejdiu answered on June 6, 2019 15:48

Currently it takes the default routing that I have defined, does not take into consideration the {nodeAlias} makro to use the alias. There is no error message just the URL is not the right one.

I think instead it uses the default one:

            var route = routes.MapRoute(
            name: "DefaultWithCulture",
            url: "{culture}/{controller}/{action}",
            defaults: new { culture = defaultCulture.Name, controller = "Home", action = "Index" }
        );
0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on June 6, 2019 16:10

That makes sense. Anything that matches "{cultureCode}/{nodeAlias}", also matches default routing and as long as default routing is registered first it handles the request.

You need to adjust routing templates, so they are different.

Option one: change new route to something like "{cultureCode}/content/{nodeAlias}", Option two: make action in default route required (remove default value for it)

I understand that none of the above options might work for you, I'm trying to provide you with idea of why it doesn't work and what could work.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.