Meryovi
Meryovi

Reputation: 6231

Lowercase URLs without affecting parameters

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?

Upvotes: 13

Views: 4867

Answers (1)

technicallyjosh
technicallyjosh

Reputation: 3531

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!

Upvotes: 11

Related Questions