HtmlEncode是做什么的?

来源:百度知道 编辑:UC知道 时间:2024/06/03 17:20:44
新手,

编码中文 unicode字符到 html 编码格式的。

比如 你在浏览器中 输入 http://hi.biadu.com/你想干什么/这样感觉不好

这时就需要用
string url = Server.HTMLEncode( "http://hi.biadu.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 DB