Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Add special characters in URL
//Tested in EPiServer CMS 11
using System;
using System.Configuration;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using EPiServer.Web;
namespace Alloy.Business
{
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class SpecialCharactersInUrlModule : IConfigurableModule
{
private string specialCharacters;
private string AllowedSpecialCharaters
{
get
{
if (string.IsNullOrEmpty(specialCharacters))
{
//Add a value in App settings
//e.g. ßöäü
specialCharacters = Convert.ToString(ConfigurationManager.AppSettings["AllowedSpecialCharaters"]);
}
return specialCharacters;
}
}
public void Initialize(InitializationEngine context)
{
//Do Nothing
}
public void Uninitialize(InitializationEngine context)
{
//Do Nothing
}
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Services.RemoveAll<UrlSegmentOptions>();
context.Services.AddSingleton<UrlSegmentOptions>(segmentOption => new UrlSegmentOptions() { SupportIriCharacters = true, ValidUrlCharacters = $@"\p{L}0-9\-_~\.\${AllowedSpecialCharaters}" });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment