小写网址,不影响参数 [英] Lowercase URLs without affecting parameters

查看:87
本文介绍了小写网址,不影响参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用ASP.NET MVC 4路由,并且LowercaseUrls选项设置为true,并且运行良好.我正在使用此配置:

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
            });

但是在一组特定的操作中,我有一个字符串id参数,该参数是加密的且区分大小写.

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 })

URL中的id参数被转换为小写字母,从而导致在尝试解密字符串时出错.

The id parameter in the URL gets converted to lowercase resulting in an error while trying to decrypt the string.

是否可以忽略URL参数而将路由配置为小写URL?

Is it possible to configure routing to lower-case URLs ignoring URL parameters?

推荐答案

我以前遇到过这个问题.我最终要做的是得到 AttributeRouting .

I've run into this before. What I ended up doing was getting AttributeRouting.

它们具有与 PreserveCaseForUrlParameters 相似的功能(在上方链接).

They have a sweet feature (linked above) to PreserveCaseForUrlParameters.

另一种选择是使用 LowercaseRoutesMVC .在这种情况下,您可以将某些路由设置为小写,而您希望保留的路由则可以事先使用routes.MapRoute.但是,由于特别配置的路由将变为小写,而默认路由的整个路由将变为小写,因此这可能会变得混乱.

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.

希望这会有所帮助!

这篇关于小写网址,不影响参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆