Share via


Page.URLEncode

Ee783962.c++_on(en-US,CS.10).gifEe783962.vb_off(en-US,CS.10).gif

Use this method to apply URL-encoding rules, including escape characters, to a specified string. An encoded URL string may be passed in a URL as a query string argument.

Ee783962.important(en-US,CS.10).gif Important

  • This method is included for backwards compatibility with Site Server 3.0 Commerce Edition. See the AuthManager object, which provides similar functionality to that found in the URLEncode method. Using the AuthManager methods  is the preferred way of adding this type of functionality to your site, and will ensure better compatibility with future versions of Microsoft Commerce Server.

Definition

Function URLEncode(vtValue As Variant) As String

Parameters

vtValue

A Variant that contains the string to be encoded.

Return Values

If this method completes successfully, it returns a URL-encoded String.

Error Values

This method sets the Number property of the global Err object to S_OK (&H00000000) to indicate success and to standard COM error values to indicate failure. For more information about standard COM errors, see Standard COM Errors. Additional information may be available using the global Err object. In particular, the Description property may contain a text description of the error.

Remarks

Strings that contain certain characters, such as spaces, slashes (/), or percentage symbols (%), cannot be passed as URL query arguments. URL encoding encodes these characters as escaped text so that they can be passed in a URL.

The Page.URLEncode method is equivalent to the Server.URLEncode method, except that the Page.URLEncode method handles NULL values by returning an empty string. (The Server.URLEncode method fails when the String parameter is NULL). This distinction is important because database queries can return NULL.

For more information about memory ownership issues related to COM property and method parameters, see Managing COM Parameter Memory.

Example

' Suppose that a variable called referringURL contains the URL _
' https://www.microsoft.com, which is to be passed as a query 
' string argument in another URL. 
' The following script: 
<A HREF="Sample.asp?referringURL=<% = 
    oPage.URLEncode(referringURL) %>">My link</A>
' generates the following HTML:
<A HREF="Sample.asp?referringURL= _
http%3A%2F%2Fwww%2Emicrosoft%2Ecom">My link</A>
' The receiving page (Sample.asp) can use the Request method to
' get the value of the variable. The method converts the string 
' back to its original form and returns it to the script on the page.

See Also

Page Object

AuthManager Object

Page.HTMLEncode


All rights reserved.