URLEncode/Decode

  • Thread starter Thread starter Nic
  • Start date Start date
N

Nic

Hello all,

I ran into a problem encoding/decoding special characters in URLs.
by using Server.UrlEncode and Server.UrlDecode.
Basically, encoding x+y results in x%2by, however decoding
x%2by results in x y (missing the +).

Anyway to solve this?

Thanks,

Nic
 
Nic said:
Hello all,

I ran into a problem encoding/decoding special characters in URLs.
by using Server.UrlEncode and Server.UrlDecode.
Basically, encoding x+y results in x%2by, however decoding
x%2by results in x y (missing the +).

This does not happen to me:

Console.WriteLine( HttpUtility.UrlDecode( "x%2by"));


I'm guessing that what's happening is that you're passing in to
UrlDecode a string that you've gotten from Request.QueryString[] (or
something similar).

The strings in the QueryString collection have already been decoded, so
you would be in effect decoding the string twice which would result in
the behavior you're seeing ('+' gets decoded into a space).
 
Mike, thanks for your reply. You're right, the string I am passing is
already decoded by
Request.QueryString

Nic
mikeb said:
Nic said:
Hello all,

I ran into a problem encoding/decoding special characters in URLs.
by using Server.UrlEncode and Server.UrlDecode.
Basically, encoding x+y results in x%2by, however decoding
x%2by results in x y (missing the +).

This does not happen to me:

Console.WriteLine( HttpUtility.UrlDecode( "x%2by"));


I'm guessing that what's happening is that you're passing in to
UrlDecode a string that you've gotten from Request.QueryString[] (or
something similar).

The strings in the QueryString collection have already been decoded, so
you would be in effect decoding the string twice which would result in
the behavior you're seeing ('+' gets decoded into a space).
 
Back
Top