Name

UrlDecode

Synopsis

returnstring = Server.UrlDecode(s)
Server.UrlDecode(s,output)

Returns a string in which any special character sequences resulting from encoding by the UrlEncode method (described later in this chapter) are decoded back into the original format. For example, a URL with a query string such as:

http://localhost/ASPdotNET_iaN/Chapter_18/UrlDecode.
aspx?strtodecode=This%20is%20a%20good%20string.

would return the following string from the UrlDecode method:

This is a good string.

Parameters

returnstring

A String variable to receive the decoded string from the method.

s

A String variable containing the encoded URL to be decoded by the method.

output

An instance of any class derived from the TextWriter class (found in the System.IO namespace) used to capture the decoded string. Examples are the StringWriter and HtmlTextWriter classes.

Example

The code example declares two string variables, sets the value of StrToDecode to the encoded equivalent of the QueryString’s StrToDecode value, assigns the return value of the Server.UrlDecode call to StrToReturn, and then writes the value to the browser using the Message label control:

Sub Page_Load(  )
   Dim StrToDecode As String
   Dim StrToReturn As String
   StrToDecode = Request.QueryString("StrToDecode")
   StrToReturn = Server.UrlDecode(StrToDecode)
   Message.Text = StrToReturn
End Sub

Notes

New in ASP.NET, this method provides a simple way to undo the effects of calling UrlEncode on a given string. It is especially useful for retrieving ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.