Lowercase route URLs automatically in Razor Pages 2.0

In Razor Pages 2.0, the routing system is based on file locations within the project's root directory.

navigate-urls-lowercase-project

If the project has mixed case page names, then ASP.NET will generate URLs are also mixed case.

navigate-urls-before-setting-annotated

I was about to add this to the very shortlist of things I do not like about Razor Pages; however, there is a configuration setting to enable lowercase URLs.

In Startup.cs, find the ConfigureSettings method, and make the following change:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddRouting(options => options.LowercaseUrls = true);
    ...
}

That is it!

navigate-urls-after-setting-annotated

Enjoy!

Show Comments