Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Internal url not mapping correctly when mapped through XHTML field



I have a catalog item routed through a custom partial route as "". Note that "" doesn't represent any actual page on my website.

The problem appears when I paste the link "" in any XHTML field on CMS. That link will be seen as internal and mapped to the corresponding internal link. I end up with something like "<string>.aspx?espremainingpath=items/itemA". Because "/items" does not correpond to any existing page, on GetPartialVirtualPath(), I return the BasePathRoot as the home page and include everything else in the PartialVirtualPath().

return new PartialRouteData
        BasePathRoot = "",
        PartialVirtualPath = string.Format("{0}/{1}", "items",

Unfortunatly when I click on the new generated link it will take me to the home page and will keep the espremainingpath as it is, so I would have something like "" when the behavior I would be expecting would be for the espremainingpath to be interpreted.

As I can currenctly access any items when edting the url directly I assume that I didn't miss anything when implementing the custom partial route.

Is this an issue with Episerver or am I missing something? Thank you :]

The version of Episerver CMS I am using is 11.11.2 together with c# 7.3

Edited, Mar 27, 2019 13:21

Can you try this?

var partialVirtualPath = string.Format("items/{0}", item.RouteSegment);

return new PartialRouteData
    BasePathRoot = StartPageContentLink,
    PartialVirtualPath = SegmentHelper.GetModifiedVirtualPathInEditOrPreviewMode(item.ContentLink, partialVirtualPath, requestContext.GetContextMode())
Edited, Mar 27, 2019 14:34

I tried that and I am getting the exact same result in the end. Once published and when I click on the link it redirects me to ""

Thank you for the suggestion anyways :]

Mar 27, 2019 16:19

How do you insert the link into the editor? And do you render the property in a Razor view with Html.DisplayFor or Html.PropertyFor?

Edited, Mar 27, 2019 16:24

I visit the item I want and then copy the link directly from there, which in this case would be "" where "item-A" is the item SEO URL in the CMS.

And to render the field where I copy the link to

<div class="text-content" ng-bind-html="item.description | toTrustedHtml">

May be worth mentioning that any other links that map to internal content (but that don't use a custom partial route) work fine using this same method.

Mar 27, 2019 16:46

Start with replacing @Model.ItemDescription with @Html.DisplayFor(m => m.ItemDescription), and see if that makes any difference.

You should also use the link tool in TinyMCE editor to insert link to commerce item.

Edited, Mar 27, 2019 16:50

Replacing it with @Html.DisplayFor(m => m.ItemDescription) will make it render the link exactly as I paste it (without any mapping to the internal link) which is not the solution I am looking for. The data type of the description at the viewmodel scope is HtmlString..

When using the link tool in TinyMCE the link will be pointing to the content page in CMS which in return will make the user get an 401 and be redirected to the home page instead.

Mar 27, 2019 17:52

When you say catalog item, do you mean a commerce catalog item? If you use the link tool to select a catalog item and it ends up with a 401, then there must be some issue in your partial router.

Mar 28, 2019 8:16

I am sorry, after reading your reply I went back and did it again only to see that it didn't work because of a mistake a made.

In the meanwhile I have tried creating an Initialization module where I checked the methods CreatedVirtualPath, CreatingVirtualPath, RoutedContent and RoutingContent (from IContentRouteEvents) to make sure the args parameter content was actually correct... and it was, which left me thinking it was an Episerver problem. Although it doesn't look like anyone else has said anything similiar in these past days so it has to be something I did wrong on my part.

Even though the use of the create link feature on the TinyMCE is an option, for a content team that has to deal with a catalog with thousands of different items it saves a lot of their time by being able to paste the link from the url and letting Episerver do the internal mapping automatically... I am leaving that as a last resort.

Have you got any other ideas or suggestions?

Mar 28, 2019 10:57

I tested with a similar scenario (Commerce site with custom partial router for items) and had no problems pasting the URL in TinyMCE editor. When I open up the link tool for the pasted link, it has automatically been resolved as a "Catalog content" link type. But we are rendering the HTML with Html.PropertyFor and the data type on the model is XhtmlString.

Mar 28, 2019 12:17

Hi Mattias,

I have been working on different things since your last response and when I got back to this issue I decided to test a different implementation of the Partial Router.

Previously I was using a implementation that inherited the class HierarchicalCatalogPartialRouter and now I have replaced this with an implementation of the interface IPartialRouter (the differences between this two were really small) but with this change I was able to get my problem solved.

The last thing missing is to understand what was really happening here as I still have no idea. I tried reading both classes page on the Episerver documentation (for the version of Episerver I am using) but unfortunatly I had no luck there as they don't have that much relevant information for HierarchicalCatalogPartialRouter. Perhaps you have more insigh on this topic that you could share with me? 

Thank you!

May 01, 2019 11:46
* 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.