Try our conversational search powered by Generative AI!

How does CharacterMap in UrlSegmentOptions work?

Vote:
 

Hi,

According to https://world.episerver.com/documentation/developer-guides/CMS/routing/internationalized-resource-identifiers-iris/ (at the bottom of the page) CharacterMap in UrlSegmentOptions is a map for converting one char that is not suported in the url to another suported char.

"UrlSegmentOptions also exposes a CharacterMap property, where it is possible to define a mapping for unsupported characters, for example 'ö' => 'o'. "

But if I switch an "a" for an "ä" in a valid url I get a 404 resonse insted of the page for the valid url. Am I understanding the function of CharacterMap wrong?

I use CMS 10

Best regards
Jesper

#179384
Edited, Jun 09, 2017 11:11
Vote:
 
#179391
Jun 09, 2017 12:41
Vote:
 

The character map is not used during routing of a request request (that is it will not be used to e.g. map 'ä' to 'a' during segment parsing). It is used when an url segment is created. So e.g. given that you have a regexp definied in

UrlSegmentOptions.ValidUrlCharacters 

that does not allow for character 'ä' it will then use the charater map to see if the unallowed character should be replaced with something e.g. 'ä' => 'a' when the url segment is created
#179406
Jun 12, 2017 9:59
Vote:
 

Thanks John for clarifing that.

Is there a similar character map for the segment parsing? Or any other way to replas characters before segment parsing?

#179411
Jun 12, 2017 11:16
Vote:
 

There is no similar map used at routing. What you probably could do is hook up an event handler to 

EPiServer.Web.Routing.IContentRouteEvents.RoutingContent

On the eventargs (of type RoutingEventArgs) you could access the path as args.RoutingSegmentContext.RemainingPath and update it (e.g. by replacing 'ä' => 'a')

#179414
Jun 12, 2017 11:56
Vote:
 

Thanks again Johan!

I will look in to that possible solution.

#179424
Jun 12, 2017 12:21
Vote:
 

This is the code for my sulotion based hon Johans sugestion. If anybody in the future should need it =)

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule),
typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class EventInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var contentRouteEvents = ServiceLocator.Current.GetInstance<IContentRouteEvents>();
contentRouteEvents.RoutingContent += RoutingEvents_RoutingContent;
}

public void Uninitialize(InitializationEngine context)
{

}

private static void RoutingEvents_RoutingContent(object source, RoutingEventArgs e)
{
e.RoutingSegmentContext.RemainingPath = e.RoutingSegmentContext.RemainingPath.
Replace("ö", "o").
Replace("Ö", "o").
Replace("å", "a").
Replace("Å", "a").
Replace("ä", "a").
Replace("Ä", "a");
}
}

#179428
Jun 12, 2017 13:58
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.