Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlEncoding Plus(+) in URL in ASP.Net

Tags:

url

asp.net

I'm encrypting and Base64 a string. Everything works great, until I retrieve the encrypted string from the QueryString collection. The Encrypted text contains a plus symbol. When I retrieve the encrypted string, where a plus once was there is now a space. As you can imagine this doesn't decrypt.

I have tried both Server.HtmlEncode/HtmlDecode and Server.UrlEncode/Server.UrlDecode with no avail. Both methods confuse the plus symbol with the space.

Any idea's?

Here is a similar post: QueryString Malformed

Edit: I found the solution: Server.UrlEncode does work, I was applying Server.UrlDecode and didn't need too.

like image 200
Chuck Conway Avatar asked Jan 25 '26 02:01

Chuck Conway


1 Answers

Be careful, the method of substituting "+++" for "==" is dangerous because in rare situations, it is possible for an encrypted query string to validly contain "+++". In this case, the decryption fails. For a better solution to the problem, look at using the "modified base64 for url". It involves switching out "-" for "+" and "_" for "/" and has no "==" padding. It seems to be working for us, even in situations where the other failed. Here is the link I used for reference that is working for us.

Code for decoding/encoding a modified base64 URL

like image 74
Brian Ellis Avatar answered Jan 27 '26 14:01

Brian Ellis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!