3

If we ask the MVC framework to generate URLs for us, for example by using UrlHelper inside a controller, the route segments in the generated URL will be upper case.

[Route("[controller]")]
public class PeopleController : Controller
{
    [HttpGet]
    public IActionResult Get()
    {
        var url = this.Url.Action("Get", "People"); // Returns "/People"

        ...
    }
}

How is it possible to tell MVC to generate lower case routes instead, so in the above example, return "/people"?

1 Answer 1

9

It's simple to achieve this, in the ConfigureServices method of our Startup class we just have to configure routing by setting the LowerCaseUrls property to true.

public class Startup
{
    ...

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRouting(routeOptions => routeOptions.LowercaseUrls = true);

        ...
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.