Lowercase URLs without affecting parameters

走远了吗. 提交于 2020-01-31 07:07:20

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/17243847/lowercase-urls-without-affecting-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!