Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Server.HTMLEncode Method

IIS 6.0

The HTMLEncode method applies HTML encoding to a specified string. This is useful as a quick method of encoding form data and other client request data before using it in your Web application. Encoding data converts potentially unsafe characters to their HTML-encoded equivalent.

If the string to be encoded is not Double-Byte Character Set (DBCS), HTMLEncode converts characters as follows:

  • The less-than character (<) is converted to &lt;.

  • The greater-than character (>) is converted to &gt;.

  • The ampersand character (&) is converted to &amp;.

  • The double-quote character (") is converted to &quot;.

  • Any ASCII code character whose code is greater-than or equal to 0x80 is converted to &#<number>, where <number> is the ASCII character value.

If the string to be encoded is DBCS, HTMLEncode converts characters as follows:

  • All extended characters are converted.

  • Any ASCII code character whose code is greater-than or equal to 0x80 is converted to &#<number>, where <number> is the ASCII character value.

  • Half-width Katakana characters in the Japanese code page are not converted.

HTMLEncode(
   string
)

string

Specifies the string to encode.

This method has no return values.

The following script:


<%= Server.HTMLEncode("The paragraph tag: <P>") %>  


Produces the following output:

The paragraph tag: &lt;P&gt;

The preceding output will be displayed by a Web browser as:

The paragraph tag: <P>

If you view source, or open the page as a text file, you will be able to see the encoded HTML.

Applies To

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

Show:
© 2015 Microsoft