mariocatch mariocatch - 3 months ago 25
ASP.NET (C#) Question

How do you enforce lowercase routing in ASP.NET Core MVC 6?

In ASP.NET 4 this was as easy as

routes.LowercaseUrls = true;
in the
RegisterRoutes
handler for the app.

I cannot find an equivalent in ASP.NET Core MVC6 for achieving this. I'd think it would be here:

app.UseMvc(configureRoutes =>
{
configureRoutes.MapRoute("Default", "{controller=App}/{action=Index}/{id?}");
});


But nothing in
configureRoutes
looks to allow it... unless there's an extension method somewhere that I can't find in the docs perhaps?

Answer

Found the solution.

In the assembly: Microsoft.AspNet.Routing, and the Microsoft.Extensions.DependencyInjection namespace, you can do this in your ConfigureServices(IServiceCollection services) method:

services.ConfigureRouting(setupAction =>
{
    setupAction.LowercaseUrls = true;
});
Comments