asp学习网: 首页 >> asp.net >> .NET中的HTML编码和URL编码

.NET中的HTML编码和URL编码

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>
from:asp学习网/title:.NET中的HTML编码和URL编码/ time:2007-6-13 23:12:05

本文主题编码,.NET

ASP.NET 四种判断浏览器类型(ENGLISH)

ASP.Net中的时间处理中的时间处理

ASP.NET 2.0 绑定高级技巧

asp.net与数据库初步

老铁:从ASP过渡到.net遗留的二十大积习

.NET之ASP Web Application入门

ADO.NET 2.0 功能一览

在.Net中访问操作MySQL数据库

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行