ProgramFan.com
回到首页 设为首页 加入收藏 网站留言
人才招聘频道
编程爱好者BLOG
编程爱好者论坛
首页 | 论坛 | BLOG | 人才招聘 | 书评 | 文章 | 资讯 | 下载 | 源码 | 项目交易 | 兴趣小组 | 网友作品 | 资源共享 | 收藏夹 | ACM题库 | VBAPI查询 | 刻盘服务
 您所在的位置:编程爱好者网站文档中心ASP.net文章 - 正文
 

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

(加入日期:2002-6-14 点击数:11285)
收藏文章】【对此文发表评论】【保存文章至硬盘】【打印文章】【字体:


导 读: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>
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( ProgramFan.Com )

对此文发表评论】 【编程爱好者论坛】 【关闭窗口

 
 
 
 
 
 

最新招聘信息

 
 


关于本站 - 网站导航 - 广告服务 - 诚邀加盟 - 联系站长友情链接赞助本站
Copyright© 1999-2008 Programfan.com. All Rights Reserved
网站制作&维护:Hannibal    Email: webmaster@pfan.cn