vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, May 28, 2012

How to pass ampersand (&) symbol in URL in asp.net


Here the way to find the passing '&' symbol in URL. Basically in URl '&' symbol has treated like separator in URL, Some situation we need to pass the our data with
‘&’ symbol, in such case if you pass directly it will split the data with using & symbol, you would get the desired result you need.

Here am illustrating with one example...
You have a name like..&vnam=John&jeorge
If you pass the vnam in URL, it will treat '&' symbol as a delimiter or separator
In such cases we have to use common function called URL encode.
For using this function you need use import namespace as

Import System.web;

   Dim str As String = HttpUtility.UrlEncode("John&jeorge")
&vnam=str

Now the & sysmbol has been replaced %20, By using this method you don’t get any errors by passing ‘&’ symbol in URL. In another side  decode the url using
str = HttpUtility.UrlDecode(str)
Also we can encode the object into specific standard format like the below code. When decode we must use the same format to decode the object

        Dim str As String = HttpUtility.UrlEncode("John&jeorge",System.Text.Encoding.GetEncoding("ISO-8859-15")))


ISO-8859-15:
 This character set is used throughout The Americas, Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.Each character is encoded as a single eight-bit code value.

I hope you like this article …keep reading.

0 comments:

Post a Comment