Lower case URLs in ASP.NET Core

Expeed Screenshot

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);

ABOUT THE AUTHOR

I’m the Technical Director at Expeed Technology in Adelaide, South Australia. In my day job I work on both Windows and Linux web hosting technologies and Windows and Web .NET development. In my spare time I tinker with video production, photograpy, and all things Azure, including IAAS, PAAS and Serverless. You can find me on Twitter over at @simonholman

Share

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Related

Comment

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Do NOT follow this link or you will be banned from the site! Scroll to Top