Lower case URLs in ASP.NET Core

Every time I start a new ASP.NET project, I forget the function required to ensure that all links generated out of ASP.NET are lowercase. So this post is as much a reminder for me, than information for anyone else.

Personally think all lowercase URLs look better rather than the usual mismatch of cases that a lot of sites have, so I always try to ensure they\’re lowercase.

There is also an SEO benefit to ensuring a consistent casing across URL’s. Google sees /product/widgets and /Products/widgets and /products/Widgets as 3 separate pages. This means that if you have 3 separate external sites linking to each of these variants, the SEO benefit to that page is significantly reduced.

Using the ASP.NET Core framework to ensure that all URLs are lowercase means that if someone adds a link to your page as /Products/Widgets or /Products/widgets , your site will return a 301 redirect to /products/widgets. Google understands that 301 redirects are your way of saying “this is the correct url for this content”.

To ensure these lower case urls are generated, all you need to do is add the following code line to your ConfigureServices method in your Startup.cs file above your call to services.AddMvc()

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

1 thought on “Lower case URLs in ASP.NET Core”

Comments are closed.

Scroll to Top