电脑技术网——专业手机电脑知识平台,关注科技、手机、电脑、智能硬件
JavaScriptASP编程PHP编程Python编程ASP.NET

ASP.NET 中的 HTML 编码和 URL 编码

2020-01-03 08:06:15 出处:[ 菜菜电脑网 ] 人气:次阅读

;大 念书: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>

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

©CopyRight 2008-2020 caicaipc.com Inc All Rights Reserved.
菜菜电脑网 版权所有