GenoPro Developer Home
GenoPro Home  |  SDK Home  |  Report Generator  |  Support  |  Search  |  Help  |  Site Map

Skip Navigation Links.

Util.UrlEncode Method

Encodes an input string to produce a valid URL string for use in the browser. For instance, space characters and punctuation are not allowed in the URL, so all spaces are converted to a plus sign and all non-alphanumeric characters are converted to their hexadecimal value of format %nn.

The UrlEncode method produces the same output as Server.UrlEncode in ASP.

You may use the UrlEncode method to encode a full URL, however its main use is to encode the query string values of the URL.

strName = "André & Hélène"
strURL = "" & Util.UrlEncode(strName)
Report.Write "<a href='" & strURL & "'>Login</a>"

' Output: <a href=''>Login</a>

Double Encoding Warning:
The method UrlEncode should be used with care. An non-encoded URL does produce an error, however a double-encoded URL does produce incorrect result. For instance, the following piece of code shows the double-encoding of an URL.

strURL = ""
Report.WriteBr strURL
Report.WriteBr Util.UrlEncode(strURL)
Report.WriteBr Util.UrlEncode(Util.UrlEncode(strURL))

Report.WriteBr Util.HrefEncode(strURL)
Report.WriteBr Util.HrefEncode(Util.HrefEncode(strURL))
Report.WriteBr Util.HrefEncode(Util.UrlEncode(strURL))

' Output:
' http%3A%2F%2Fwww%2Egenopro%2Ecom%2F%3Fid%3Dabc
' http%253A%252F%252Fwww%252Egenopro%252Ecom%252F%253Fid%253Dabc
' http%3A%2F%2Fwww%2Egenopro%2Ecom%2F%3Fid%3Dabc

As you can see, the double-encoding of the URL does produce a different result. One must be careful not to double-encode in the following scenario:

strName = "André & Hélène"
strURL = "" & Util.UrlEncode(strName)
Report.Write "<a href='" & Util.UrlEncode(strURL) & "'>Login</a>"

In this example, the strName has been encoded twice which is incorrect. The safe solution to this is to use HrefEncode, because HrefEncode does not encode any character if the URL is already valid.

To see more samples of URL encoding, please consult the method HrefEncode.

See Also:


Copyright © 1998-2014. All rights reserved. GenoPro® and the GenoPro logo are registered trademarks.