System.Web.HttpServerUtility.HtmlEncode Method

HTML-encodes a string and sends the resulting output to a System.IO.TextWriter output stream.

Syntax

public void HtmlEncode (string s, System.IO.TextWriter output)

Parameters

s
The string to encode.
output
The System.IO.TextWriter output stream that contains the encoded string.

Remarks

HTML encoding ensures that text will be correctly displayed in the browser, not interpreted by the browser as HTML. For example, if a text string contains a less than sign (<) or greater than sign (>), the browser would interpret these characters as an opening or closing bracket of an HTML tag. The HTML encoding of these two characters is &lt; and &gt;, respectively, which causes the browser to display the less than sign and greater than sign correctly.

erload:System.Web.HttpServerUtility.HtmlEncode is a convenient way to access the erload:System.Web.HttpUtility.HtmlEncode method at run time from an ASP.NET application. Internally, erload:System.Web.HttpServerUtility.HtmlEncode uses erload:System.Web.HttpUtility.HtmlEncode to encode strings.

To encode or decode values outside of a web application, use the System.Net.WebUtility class.

Requirements

Namespace: System.Web
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0