Decoding in URL encoding and decoding in ASP. NET

Source: Internet
Author: User
Tags urlencode
ASP. NET In URL Encoding Decoding

Today, the project needs to post data to the ASP Client URL, but the URL Chinese cannot be used. In the afternoon, ASP andAsp.netOfURL EncodingDifferent things:

Let's take a look at the following two URLs. Are they passing the same parameters?
AAA. aspx? Tag =. Net % BC % Ca % F5
AAA. aspx? Tag =. Net % E6 % 8A % 80% E6 % 9C % af

It seems to be different, in fact they are on the ". NET Technology" urlencode, but one is gb2312 encoding, one is the Utf-8 code.
As follows:CodeYou can get the above encoding effect:

String tmp1 = system. Web. httputility. urlencode (". NET technology", system. Text. encoding. getencoding ("gb2312 "));
String tmp2 = system. Web. httputility. urlencode (". NET technology", system. Text. encoding. utf8 );

Our actual web page may beProgramCall.
For example, an ASP page on a simplified Chinese operating system needsAsp.netThe page passes a parameter with Chinese characters.
By default, on the simplified Chinese operating system, ASP server. urlencode will encode Chinese in gb2312 encoding,
However, by default,Asp.netThe page is encoded in UTF-8.
In this case, when you use request. querystring ["tag"] to accept the value, you will not be able to accept the Chinese information. What you can see in One-Step debugging is garbled characters.
At this time, although request. querystring ["tag"] is used to accept garbled characters, the URL at this time is not garbled.

The solution is to analyze the parameters in the URL, and then the parameter value according to gb2312 Encoding Anti-decryption, rather than using. Net default Utf-8 Encoding Anti-decryption.

Also:. Net hasServer. urlencode ()AndSystem. Web. httputility. urlencode () can all be encoded.

The difference is that httputility. urlencode () is UTF-8 encoded by default, while server. urlencode () is UTF-8 encoded by default.

C #Asp.netThe URL must use system. Web. httputility. urlencode instead of server. urlencode to pass Chinese parameters.!!!

The default aspx is UTF-8 encoded. In my program, gb2312 must be used as the default encoding.
(<Globalization requestencoding = "gb2312" responseencoding = "gb2312"/>)

Today, the project needs to post data to the ASP Client URL, but the URL Chinese cannot be used. In the afternoon, ASP andAsp.netOfURL EncodingDifferent things:

Let's take a look at the following two URLs. Are they passing the same parameters?
AAA. aspx? Tag =. Net % BC % Ca % F5
AAA. aspx? Tag =. Net % E6 % 8A % 80% E6 % 9C % af

It seems to be different, in fact they are on the ". NET Technology" urlencode, but one is gb2312 encoding, one is the Utf-8 code.
The following code gets the effect after encoding:

String tmp1 = system. Web. httputility. urlencode (". NET technology", system. Text. encoding. getencoding ("gb2312 "));
String tmp2 = system. Web. httputility. urlencode (". NET technology", system. Text. encoding. utf8 );

Our actual web page may be called by other programs.
For example, an ASP page on a simplified Chinese operating system needsAsp.netThe page passes a parameter with Chinese characters.
By default, on the simplified Chinese operating system, ASP server. urlencode will encode Chinese in gb2312 encoding,
However, by default,Asp.netThe page is encoded in UTF-8.
In this case, when you use request. querystring ["tag"] to accept the value, you will not be able to accept the Chinese information. What you can see in One-Step debugging is garbled characters.
At this time, although request. querystring ["tag"] is used to accept garbled characters, the URL at this time is not garbled.

The solution is to analyze the parameters in the URL, and then the parameter value according to gb2312 Encoding Anti-decryption, rather than using. Net default Utf-8 Encoding Anti-decryption.

Also:. Net hasServer. urlencode ()AndSystem. Web. httputility. urlencode () can all be encoded.

The difference is that httputility. urlencode () is UTF-8 encoded by default, while server. urlencode () is UTF-8 encoded by default.

C #Asp.netThe URL must use system. Web. httputility. urlencode instead of server. urlencode to pass Chinese parameters.!!!

The default aspx is UTF-8 encoded. In my program, gb2312 must be used as the default encoding.
(<Globalization requestencoding = "gb2312" responseencoding = "gb2312"/>)

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.