Try our conversational search powered by Generative AI!

Custom route bug


I've followed Jon's excellent post here:

So I have a custom route that initially works as expected - browsing passes 'searchterm' to my controller, giving me a nice, friendly URL. Using querystring parameters also works (

Here's the problem:

If I create a link in the TinyMCE editor to a page that matches the route: (like, things get weird.

Initially, viewing the HTML shows the link in the friendly format: If I check the database at this point, it's stored like this: “~/link/some-guid.aspx?epsremainingpath=searchterm”. Browsing the site after the first publish, the link works as expected.

However, if I edit the page again and view the HTML, the link is now shown in this format: "/episerver/CMS/Content/,,1040/searchterm?epieditmode=False&epsremainingpath=searchterm". After saving the page, the database is now updated with this value. Now anyone browsing the page will also be presented with this link, which does not resolve to the friendly URL. So essentially, subsequent edits to a page break any links on the page that match the route! This is quite a nasty error, because a page author can basically break all links without touching them. It doesn't break if I use the querystring format (

I've also just tried following Joels post here, using an Initializable module: Interestingly, the GetVirtualPathSegment method never gets hit, and ultimately I get the same problem.

Can anyone replicate this issue? Anyone have an idea how to fix it?


May 20, 2016 6:12

Hey! I just saw this post:

Could be the same issue: I tried the protocol-relative URL - instead of, id did // and it seems to have worked.

May 20, 2016 6:21


The reason you get that behaviour is that during the second post from the editor the link looks like "/episerver/CMS/Content/,,1040/searchterm?epieditmode=False&epsremainingpath=searchterm" as you noticed. However for this url your custom route will not match since there is segments /episerver/Cms/Content/ first and also a segment /,,1040/. And hence no route matches the url CMS assumes it is an external link and saves it untouched. So what you need to do is to register an additional route that handles the edit format of the link. Like:

                  name: "searchterm",
                  url: CmsHomePath + "{language}/{nodeedit}/{partial}/{action}/{page}",
                  defaults: new { action = "index" },
                  parameters: parameters);
where CmsHomePath is defined as:
 private static string CmsHomePath
            var cmsContentPath = VirtualPathUtility.AppendTrailingSlash(ModuleResourceResolver.Instance.ResolvePath("CMS", "Content"));
            //Remove application specific path if exist.
            return VirtualPathUtilityEx.ToAppRelative(cmsContentPath).Substring(1);
May 20, 2016 15:35

Awesome, thank Johan. Adding that extra route basically fixed it.

The issue discussed here:  is happening, but we can live with that for now. 

Essentailly, I can add a link in the 'External link' text field and it ends up as a page reference in the 'Page' textfield, minus the '/searchterm'. However, the link still works as expected (using the HTML button in TinyMCE shows the full path.) Editing is a bit annoying, but at least the page doesn't break anymore.

Interestingly, using the 'classic' link dialog just shows the full internal path, like ",,1040/searchterm?epieditmode=False&epsremainingpath=searchterm", which possibly makes editing a bit easier.


May 23, 2016 4:07

So, it's been a while, but I've encountered another bug related to this implementation of custom routes.

Johan's fix works for the TinyMCE editor, but I get another error when using the page 'Shortcut' (redirect) feature (All properties > Settings tab > Shortcut).

Let's say we have, where searchterm is the parameter.

If I create another regular page, then set it's 'Shortcut' property to '', I have to use the 'Shortcut to page on another website' option because of the URL parameter. When I save the page, this URL is changed to ~/link/some GUID.aspx?epsremainingpath=searchterm. So now the Shortcut/redirect is broken.

the only workaround I can use is to enter an external URL using traditional querystring format, like


Oct 12, 2017 4:53
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.