Asp. HTML encoding and URL encoding in net

Source: Internet
Author: User
Tags urlencode

Introduction: Server.HTMLEncode and Server.URLEncode are commonly used in ASP functions, in the asp.net also have similar functions: HTMLEncode and UrlEncode (note case) below with an example to introduce.

Server.HTMLEncode and Server.URLEncode are very common functions used
by ASP developers. So, as may have guessed two functions
have asp.net counterparts. HtmlEncode and UrlEncode (notice case) are
Part of the System.Web.HttpUtility namespace.

This is the demo

urlencode.asp?test=1&test1=2
Urlencode.asp%3ftest%3d1%26test1%3d2


This is a test & hopefully it works!

**********************************
This is the code:
**********************************

<%@ Page language= "VB"%>
<%@ Import namespace= "System.Web.HttpUtility"%>
<title>htmlencode and UrlEncode the asp.net way</title>

<script language= "VB" runat= "Server" >
Sub Page_Load (sender as Object, E as EventArgs)

' Assign we 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 We label control
Dim Strurlencodetext as String = UrlEncode (Strurltext)
Strurlencode.text = Strurlencodetext

' Assign we test URL to a variable, Assign the variable to our
Label control
Dim strHTMLText as String = "Works!Strhtml.text = strHTMLText

' Encode the ' test HTML, assign it to a variable, assign the
Variable to We label control
Dim Strhtmlencodetext as String = HtmlEncode (strHTMLText)
Strhtmlencode.text = Strhtmlencodetext

End Sub
</script>
<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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.