mariocatch mariocatch - 1 year ago 108
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?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download