Skip to content

Instantly share code, notes, and snippets.

@khurramkhang
Created December 5, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khurramkhang/ac990704c01d8c05904f27a09d3bf93c to your computer and use it in GitHub Desktop.
Save khurramkhang/ac990704c01d8c05904f27a09d3bf93c to your computer and use it in GitHub Desktop.
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