Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

I had a function, that took the field BARCODE from the database and created URL string for Redirect with parameter ?barcode=BarcodeValue.

It worked fine for a while, because most of values were numeric or alpha-numeric.

However when  barcode has 'plus' sign in front, e.g '+2134214', on the target page

Request.QueryString("Barcode") replaces the 'plus' sign with space and returns   ' 2134214' ,which is obviously not expected

So the correct way to code is to use HttpUtility.UrlEncode , if characters such as blanks and punctuation can be used in your field, e.g.

"&Barcode=" & HttpUtility.UrlEncode(Barcode).

After fixing my code I found a very detailed article Using HttpUtility.UrlEncode to Encode your QueryStrings.

Posted on Tuesday, March 6, 2007 12:19 PM ASP.NET | Back to top

Comments on this post: Always use UrlEncode, when passing parameters to Url string

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: