mariocatch mariocatch - 7 months ago 43
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
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
looks to allow it... unless there's an extension method somewhere that I can't find in the docs perhaps?


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;