views:

21

answers:

1

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

A: 

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

Jason
Yes, in effect it does double-encoding. But Why?? it does a correct encoding with white space and not with simbol! So it' s normal that if I mae Server.UrlEncode I get a double-encoding :(
Ivan90
Server.UrlEncode("c#") returns "c%23" right? Something is calling UrlEncode a second time on you. Commercial frameworks tend to come in two flavors. Either they encode everything for you, or they encode nothing. It's in-house frameworks that almost always do a little of both, or the same thing twice.I'd try not encoding it at all. If that doesn't work, then you need to look at your own code and get ALL of your calls to Server.UrlEncode at the same layer of your app. Otherwise you'll play whack-a-URL forever.
Jason