HTML and URL encoding in ASP. NET

Source: Internet
Author: User
Tags urlencode
Read export: Server. HTMLEncode and Server. URLEncode is a common function in ASP. NET also has similar functions: HtmlEncode and UrlEncode (case sensitive) are described in the following example.
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 % 3 ftest % 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
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 = "
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.