Поделиться через


Server.HTMLEncode Method

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 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
)

Parameters

  • string
    Specifies the string to encode.

Return Values

This method has no return values.

Example Code

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

Server Object

Requirements

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

See Also