I'm currently using ASP.NET MVC 4 Routing with the LowercaseUrls
option set to true
and it's working great. I'm using this configuration:
routes.LowercaseUrls = true;
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {
controller = "Inicio",
action = "Index",
id = UrlParameter.Optional
});
But in a particular set of actions, I have a string id
parameter that is encrypted and case-sensitive.
Then, when I try to generate an action link like this:
@Html.ActionLink("My Text", "Action", "Controller", new { id = encryptedString })
The id
parameter in the URL gets converted to lowercase resulting in an error while trying to decrypt the string.
Is it possible to configure routing to lower-case URLs ignoring URL parameters?
Stick to one version: The lowercase pattern is recommended (because there will always be people who will link to this more traditional version). Use 301 redirects: If you see URLs with capital letters get into index (someone linked to it or you changed your content management system and it capitalized some URLs).
Southern. Google's John Mueller clarifies that URLs are case sensitive, so it matters whether the characters are uppercase or lowercase. Variations in cases can make one URL different from another, similar to how a URL with a trailing slash is different from a URL without the slash.
An Internet address is only case sensitive for everything after the domain name. For example, it does not matter if you use uppercase or lowercase with "computerhope.com," it still reaches the same page. However, when typing the name of the page, file, or directory in the URL, it is case sensitive.
htaccess you can use mod_rewrite with an Apache expression in a RewriteCond directive to make use of the tolower() function. This redirects/corrects any URL containing uppercase letters to the same - all lowercase - URL.
I've run into this before. What I ended up doing was getting AttributeRouting.
They have a sweet feature (linked above) to PreserveCaseForUrlParameters.
The other option is to use LowercaseRoutesMVC. In this scenario you would make certain routes lowercase and the ones you want to leave alone you can just use routes.MapRoute
beforehand. However, this can get messy since the specially configured ones will be lowercase where the entire route of the default ones wouldn't be.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With