
HttpServerUtility | 503
System.Web
Namespace
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
HttpServerUtility
System.Web (system.web.dll)
sealed class
This class provides helper methods and is available through the built-in Server object. It
provides the useful UrlEncode( ) method, which converts a string into a form suitable for
use as a query string variable, and the HtmlEncode( ) method, which converts nonlegal
HTML characters in a string into the equivalent HTML entity (i.e., "<" is converted to
<) so they can be displayed on a page. Some ASP.NET web controls (like buttons) do
not require this conversion, but label controls do. You may need to use the HtmlEncode( )
method manually if you bind a field with URL information from a database. It also
always a good idea to use HtmlEncode( ) before displaying user-supplied content to
prevent possible script injection attacks.
The HttpServerUtility class provides the MapPath( ) method, which takes a string repre-
senting a virtual path and returns the real (physical) path (for example, it could
convert "/myapp/index.html" to "E:\Inetpub\wwwroot\myapp\index.html"). It also provides a
CreateObject( ) method for instantiating a COM object by using its ProgID (i.e.,
objInfo=Server.CreateObject ("MSWC.MyInfo");) and the two flow control methods Execute( ) and
Transfer( ). The Execute( )