HtmlEncode是做什么的?50
发布网友
发布时间:2023-09-25 12:56
我来回答
共3个回答
热心网友
时间:2024-11-10 20:34
编码中文 unicode字符到 html 编码格式的。
比如 你在浏览器中 输入 http://hi.bia.com/你想干什么/这样感觉不好
这时就需要用
string url = Server.HTMLEncode( "http://hi.bia.com/你想干什么/" ) ;
然后就可以用下面语句来跳到那个网页上去。
Server.Redirect(url);
编码后的中文字符都会变成 %CE%D2%CA%C7&什么的,
你试一下就知道了
另外就是 可以把< > 等不安全的字符串改成 html编码, 这样在客服端呈现出来的时候才能避免不正常的显示。
string url = Server.HTMLEncode( "<input type = input value=hahahha>" ) ;
textBox1.text = url;
这是MNSDN的解释
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 <.
The greater-than character (>) is converted to >.
The ampersand character (&) is converted to &.
The double-quote character (") is converted to ".
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.
热心网友
时间:2024-11-10 20:34
HTMLEncode
HTMLEncode 方法对指定的字符串应用 HTML 编码。
语法
Server.HTMLEncode( string )
参数
string
指定要编码的字符串。
示例
脚本
<%= Server.HTMLEncode("The paragraph tag: <P>") %>
热心网友
时间:2024-11-10 20:35
简单的说就是HTML代码过滤 不会让HTML代码在服务端运行