bannerepitutorial

EPiServer 7 : Enforcing Lower Case Url’s

This post is short and simple.  Out of the box EPiServr does not provide a way to enforce lowercase Url’s.  Out of all the solutions I’ve seen on the web, the main one by Joel Abrahamsson uses Url Segment to make the Url lower case when the page is created. We had a requirement to enforce no page segments could be uppercase and this didn’t prevent users from updating it afterwards.

So, instead of using Url Segments within my module I hooked into the SavingPage event and used lowercase the Url Segment. Sample can be found on GitHub, to add to your project just include it!

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class LowercaseUrlModule : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
DataFactory.Instance.SavingPage += SavingPage;
}
private void SavingPage(object sender, PageEventArgs e)
{
try
{
e.Page.URLSegment = e.Page.URLSegment.ToLowerInvariant();
}
catch (Exception ex)
{
// If there's a problem don't prevent the page being saved
}
}
public void Uninitialize(InitializationEngine context)
{
DataFactory.Instance.SavingPage -= SavingPage;
}
public void Preload(string[] parameters)
{
}

Note Make sure you also uninitialize it as well!

https://github.com/jondjones/EpiserverLowerCaseUrlModule

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *