ASP.NET 中的 HTML 编码和 URL 编码
2019-06-14 08:05:24来源: 阅读 ()
导 读:server.htmlencode 和 server.urlencode 是asp中很常用的函数,在asp.net中也有类似的函数:htmlencode 和 urlencode (注意大小写)以下用实例来进行介绍。
server.htmlencode and server.urlencode are very common functions used by asp developers. well, as you may have guessed, these two functions have asp.net counterparts. htmlencode and urlencode (notice case) are part of the system.web.httputility namespace.
here is the demo
urlencode.asp?test=1&test1=2
urlencode.asp%3ftest%3d1%26test1%3d2
this is a test & hopefully it works!
<h1>this is a test & hopefully it works!</h1>
**********************************
here is the code:
**********************************
<%@ page language="vb" %>
<%@ import namespace="system.web.httputility" %>
<html>
<head>
<title>htmlencode and urlencode the asp.net way</title>
<script language="vb" runat="server">
sub page_load(sender as object, e as eventargs)
assign our test url to a variable, assign the variable to our
label control
dim strurltext as string = "urlencode.asp?test=1&test1=2"
strurl.text = strurltext
encode the test url, assign it to a variable, assign the
variable to our label control
dim strurlencodetext as string = urlencode(strurltext)
strurlencode.text = strurlencodetext
assign our test url to a variable, assign the variable to our
label control
dim strhtmltext as string = "<h1>this is a test & hopefully it
works!</h1>"
strhtml.text = strhtmltext
encode the test html, assign it to a variable, assign the
variable to our label control
dim strhtmlencodetext as string = htmlencode(strhtmltext)
strhtmlencode.text = strhtmlencodetext
end sub
</script>
</head>
<body>
<asp:label id="strurl" forecolor="red" font-bold="true" runat=server/>
<p>
<asp:label id="strurlencode" forecolor="blue" font-bold="true" runat=server/>
<p>
<asp:label id="strhtml" forecolor="red" font-bold="true" runat=server/>
<p>
<asp:label id="strhtmlencode" forecolor="blue" font-bold="true" runat=server/>
</body>
</html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- asp.net源程序编译为dll文件并调用的实现过程 2020-03-29
- Asp.net MVC SignalR来做实时Web聊天实例代码 2020-03-29
- ASP.NET MVC中jQuery与angularjs混合应用传参并绑定数据 2020-03-29
- Asp.Net中WebForm的生命周期 2020-03-29
- ASP.NET使用Ajax返回Json对象的方法 2020-03-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash