URLEncode/Decode

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
 
M

mikeb

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

Nic

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top