Click here to Skip to main content
15,513,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting a hit from URL which contain Encoded data. I have came across a situation where this data had + sign which is getting replaced with space and I don't want it to happen.

Sample URL: http://xyz.test.com//samplepage.aspx?msg=AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ=

Above URL is sent to users through a third party application.

What I have tried:

I have used Server.UrlEncode(Request.QueryString["REF"]);
It is not replacing + sign with space, but it is replacing "=" sign with %3d.

I thought to use "replace" function to replace "space" with "+". But encrypted data can be anything. Is there another way to avoid this behavior.
Posted
Updated 18-Jul-16 3:00am
v2
Comments
Bernhard Hiller 18-Jul-16 4:19am    
What about POST instead of GET?

By design (and originally) in url space should be encoded to + and not to %20...
So the solution is - encode the url by yourself, just as you have done...
It will be clear to browser and will not change the data...
An other - probably less preferable - option is to base64 encode your data only (the part after the msg=). In this case you will have to decode manually...
 
Share this answer
 
You need to encode the msg value when you generate\redirect to the url.

C#
string url = string.Format("samplepage.aspx?msg={0}",
    System.Web.HttpUtility.UrlEncode("AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ="));
 
Share this answer
 
Comments
sopi9 18-Jul-16 5:30am    
I am not generating URL, I am getting a hit from another source. So, I don't have control over what I am getting in URL querystring
F-ES Sitecore 18-Jul-16 6:02am    
The app that instigates the request is badly written then. Your only real option is to replace " " with "+" when you read the parameter.
sopi9 18-Jul-16 7:57am    
URL is sent through a SAP application
F-ES Sitecore 18-Jul-16 8:36am    
It doesn't really matter where it comes from, you'll just need to replace " " with "+" after you read it from Request.QueryString.
sopi9 19-Jul-16 1:43am    
Thanks for reply, that is what I am doing, but, I thought there would be more elegant and authentic way to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900