1

I am trying to setup my MVC application to only accept lowercase URLs with routes.LowercaseUrls = true; within route config file but It seems it isn't working the way it is supposed to be.

For example I can access my MVC web app home page with both of below URLs.

http://localhost:58482/Home/indeX

http://localhost:58482/home/index

I want my application to change any uppercase letter in URL to lowercase. Is it possible?

Your help is much appreciated.

  • 1
    `routes.LowercaseUrls = true;` converts your url to lowercase when using the methods that generate a url (e.g. using `@Html.ActionLink()`). It does not change what a user types into the address bar. –  Dec 21 '17 at 20:15
  • @StephenMuecke Is there anyway I can force users to type lowercase urls? For example you can't type a single upper case letter in www.meaww.com. Is that achievable in asp.net mvc5? – Kawash Haidari Dec 22 '17 at 06:37
  • Of course not (you have no control over the users keyboard and what they type in the address bar - how would you like it if I took control of your keyboard). But what you can do is to check the url in the method, and then redirect back to the same method using `return RedirectToAction(...)` which will then use the `LowercaseUrls` value and convert the text you see in the address bar to lower case. But why would you want to do that? –  Dec 22 '17 at 06:42
  • @StephenMuecke for SEO reasons. I have heard that uppercase urls and lowercase urls are indexed differently however the share the same content. Do I need it ? – Kawash Haidari Dec 22 '17 at 06:46
  • If you want it foe SEO, look at the `Application_BeginRequest()` code in [this answer](https://stackoverflow.com/questions/878578/how-can-i-have-lowercase-routes-in-asp-net-mvc) –  Dec 22 '17 at 07:13

0 Answers0