Created
December 5, 2017 15:39
-
-
Save khurramkhang/ac990704c01d8c05904f27a09d3bf93c to your computer and use it in GitHub Desktop.
Add special characters in URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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