开发者

Urls parameters doesn't encoding correctly!

I'am using asp.net mvc version 1.0 and I've a problem with some parameter in a url!

My url is look like so(http://localhost:2282/Tags/PostList/c#)

 routes.MapRoute(
           "TagsRoute",
           "Tags/PostList/{tag}",
           new { controller="Tags",Action="PostList",tag = "" }
       );

In effect the problem is that开发者_如何转开发 tag paramter isn't encoding and so simbol # is ignored!

I am using an actionlink but maybe with version 1.0 isn't encoding parameter directly!

 <%=Html.ActionLink(itemtags.Tags.TagName,
                               "PostList","Tags",
                            new { tag = itemtags.Tags.TagName }, 
                            new { style = "color:red;" })%>

With this actionlink only whitespace are encoding correctly, infact asp.net mvc become asp.net%20mvc and it work fine! But c# isn't encoding :(

So I try to use Server.UrlEncode, and in effect it happen some stuff!!!

Infact c# became c%2523 but it isn't correct again because hexadecimal of # is %23!

Have you some solutions???? Route Contraints?

Thanks


You're getting double-encoding somewhere. %25 is the symbol for %, so:

'#' -> %23

'%23' -> %2523

It's difficult to figure out whether data is already encoded or not, especially once you throw utility methods into the loop (because they can call yet other utility methods that also encode the data). The only solution I've found to this that saves my hairline is to use a tagging class for data I've already encoded once, instead of passing my text as the same data type everywhere (eg, String).

Any method that encodes the data never takes a String and returns a String. It takes a String and returns an object which holds a String (encoded).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜