广东程序员人才网 | 程序员招聘网   中国程序员人才网广东招聘专区 人才查询中心      免费注册      个人简历登陆     企业招聘登陆   企业招聘管理     个人求职管理  
广东程序员人才招聘网
精确职位: 高级程序员 技术助理 技术主管 项目经理 部门经理 技术总监 系统分析员 数据库开发
专业招聘: ASP.NET ASP JSP PHP Java .Net Delphi C++ Builder C/C++ VC/MFC VB C#
遍布广东: 广州 深圳 珠海 汕头 佛山 东莞 江门 湛江 茂名 肇庆 清远 韶关 阳江 开平                      直通所有>>
全国分站: 北京 上海 天津 重庆 杭州 南京 武汉 沈阳 济南 成都 福州 长沙 南昌 西安                      更多>>
首页 职位查询 最新职位 职位导航 JAVA C/C++ .NET C# ASP.NET JSP PHP ASP SQL SERVER ORACLE 程序员人才简历 电脑教程 职场资讯
首页 > 电脑教程 > 正文 >
ASP.NET中的HTML编码和URL编码
类别:Asp.NET综合技巧 人气:47

导 读: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>

[1]

电脑教程查找
关键字:
查看所有电脑教程
 
电脑教程导航
ASP.NET ASP
JSP PHP
JAVASCRIPT VBSCRIPT
Java .Net
Delphi C/C++
C C++
C# VC
MFC VB
汇编语言 Perl
Python CGI
Office JBoss
MS_SQL Server SQL
PowerBuilder IBM DB2
Oracle VFP
Access Sybase
数据结构 Linnx
Unix Flash
HTML DHTML
XHTML MySQL
Access Photoshop
CSS wap