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); Simon Holman
.NET and Azure Developer
I write about .NET, Azure, and cloud development. Follow along for tips, tutorials, and best practices.
Related Posts
Implementing ASP.NET Core session with Redis Cache on Azure
Using Redis cache in Windows Azure to save session state for an ASP.NET Core web app is quick and easy to configure.
Should you use caching for speed?
I've seen countless videos and articles talking about adding caching to your ASP.NET website or API in order to "speed it up".
Using Redis Caching in your ASP.NET Core web app
Welcome back! In our previous videos, we covered the installation of Ubuntu on Windows 11 and explored how to install Redis Server on that Ubuntu instance.