How do you enforce lowercase routing in ASP.NET Core? Ask Question

How do you enforce lowercase routing in ASP.NET Core? Ask Question

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 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?

ベストアンサー1

For ASP.NET Core:

Add one of the following lines to the ConfigureServices method of the Startup class:

services.AddRouting(options => options.LowercaseUrls = true);

or

services.Configure<RouteOptions>(options => options.LowercaseUrls = true); 

Thanks to Skorunka for the answer as a comment. I thought it was worth promoting to an actual answer.

おすすめ記事