开发者

Extend Url Route to apply Url Encoding for each parameter

开发者 https://www.devze.com 2023-01-16 23:50 出处:网络
I am facing a problem that one of my fields need to be shown in the url contains special character (/, \\, :).

I am facing a problem that one of my fields need to be shown in the url contains special character (/, \, :).

The stupid way to handle this generate action links by using UrlEncode(). Then UrlDecode is used before consuming in controller. But I think it really stupid because too many places need to be adapted.

So, my problem is there any way to extend the url route or jus开发者_如何学Ct write my own one to achieve it?

Thanks, Mike


You can extend the System.Web.Routing.Route object to create a custom route and override the GetRouteData and GetVirtualPath methods. These are called to resolve a route's values and create a URL from given route values, respectively. However, I don't think URLs can contain URL encoded values for / (%2f) within the path portion of a URL though it is ok in a query string.

0

精彩评论

暂无评论...
验证码 换一张
取 消