
398
|
Chapter 18: The HttpServerUtility Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
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 values
passed in the query string, since these values commonly contain characters, such
as spaces and commas, that are not allowed in URLs.
When called with only the
s argument, this method returns a string. When called
with both the
s argument and output argument, the method does not return a
value; instead, the decoded string is sent to the
output writer.
UrlEncode
returnstring = Server.UrlEncode(s)
Server.UrlEncode(s, output)
Returns a string in which any characters not allowed in URLs are encoded by
using the URL literal equivalents, such as %2c for comma and + for space. This
makes it very simple to pass any string as a query string value and, thanks to the
new UrlDecode method, just as simple to retrieve the unencoded value.
Parameters
returnstring
A String variable to receive the encoded string from the method.
s
A String variable containing the value to be encoded by the method.
output
An instance of any class derived from the
TextWriter class (found in the
System.IO namespace); used to capture the encoded string. Classes derived
from TextWriter include StringWriter and HtmlTextWriter.
Example ...