LowercaseUrls = true in RouteOptions doesn't affect URLs with non-Roman characters

651 views Asked by At

In ASP.NET MVC CORE 2.0

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
    services.AddMvc();
}

<a asp-action="New-Post">New post</a>

Works fine giving URL like http://domain/controller/new-post

But this one

<a asp-action="Новая-Публикация">Новая публикация</a>

produces URL like http://domain/controller/Новая-Публикация

How to fix it to get URLs in low case only for any language?

1

There are 1 answers

1
juunas On BEST ANSWER

Seems like RouteCollection uses ToLowerInvariant() to lower-case the URL: https://github.com/aspnet/Routing/blob/032bcf43b2cefe641fc6ee9ef3ab0769024a182c/src/Microsoft.AspNetCore.Routing/RouteCollection.cs#L155

Quote from MSDN:

Returns a copy of this String object converted to lowercase using the casing rules of the invariant culture.

And from CultureInfo.InvariantCulture:

The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region.

So it will not work with other alphabets.

You should check if there is an issue on this in the Routing repo, and post one there. They'll be able to tell if it would be feasible to implement.