13

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?

3
  • I'm not sure but if you use a query string instead of a route parameter, it should leave it alone?
    – ryudice
    Commented Jun 21, 2013 at 20:36
  • It does, but I would really prefer it wasn't a query string value.
    – Meryovi
    Commented Jun 21, 2013 at 20:38
  • you may can build your own route with a IgnoreRoute disclaimer I have no idea if this can work was just a thought Commented Jun 21, 2013 at 20:41

1 Answer 1

11

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!

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.