Name

Server

Synopsis

HttpServerUtility = Page.Server

Returns an instance of the HttpServerUtility class, which exposes useful methods for working with ASP.NET requests. For more information on the HttpServerUtility class, see Chapter 18.

Parameters

HttpServerUtility

An object of type HttpServerUtility that may be used to access useful properties and methods exposed by this class.

Example

The following code example uses the Server property to access the HtmlEncode method of the HttpServerUtility class, which allows you to encode HTML tags and characters so that they will be displayed to the user, rather than interpreted and rendered by the browser:

Sub Page_Load(  )
   Message.Text = Server.HtmlEncode("<em>Hello, World!</em>")
End Sub

The HTML rendered from this page would look like the following:

<html>
   <head>
      <title>Server property example</title>
   </head>
<body>
   <span id="Message">&lt;em&gt;Hello, World!&lt;/em&gt;</span>
</body>
</html>

Notes

As with the Request and Response properties, while you can retrieve a local reference to the HttpServerUtility instance associated with the application, it is more common to access this instance directly through the Server property, as shown in this example.

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.