Correspondence between C # And JS conversion code functions

Source: Internet
Author: User

Source http://www.cnblogs.com/henw/archive/2011/11/08/2240779.html

 

JS encoding, decoding. Asp.net (C #) corresponding decoding, encoding

Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, A-Z, A-Z

Encodeuri is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, A-Z, A-Z

Encodeuricomponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, A-Z, A-Z

1.

JS:Escape:

  • You can use escape when JS uses data.
  • For example, search for the history record in the bucket.
  • When Unicode values other than 0-255 are encoded, the % u *** format is output. In other cases, escape, encodeuri, and encodeuricomponent are encoded with the same result.

Decoding: Unescape

C #:

Httputility. urlencode
Httputility. urldecode

 

2.

JS:Encodeuri:

  • Encodeuri can be used for URL redirection.
  • Example: location. href = encodeuri ("http://cang.baidu.com/do/s? WORD = Baidu & Ct = 21 ");

Decode Using decodeuri ();

C #:Decodeuricomponent

 

3.

JS:Encodeuricomponent:

  • You must use encodeuricomponent when passing parameters so that the combined URL will not be truncated by special characters such.
  • Example: <script language = "JavaScript"> document. Write ('<a href = "http://passport.baidu.com /? Logout & Aid = 7 & U = '+ encodeuricomponent ("http://cang.baidu.com/bruce42") +' "> exit </a & gt; '); </SCRIPT>

Decode Using decodeuricomponent ()

C #:

[Httpcontext. Current.] server. urldecode

[Httpcontext. Current.] server. urlencode

Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, A-Z, A-Z

Encodeuri is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, A-Z, A-Z

Encodeuricomponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, A-Z, A-Z

1.

JS:Escape:

  • You can use escape when JS uses data.
  • For example, search for the history record in the bucket.
  • When Unicode values other than 0-255 are encoded, the % u *** format is output. In other cases, escape, encodeuri, and encodeuricomponent are encoded with the same result.

Decoding: Unescape

C #:

Httputility. urlencode
Httputility. urldecode

 

2.

JS:Encodeuri:

  • Encodeuri can be used for URL redirection.
  • Example: location. href = encodeuri ("http://cang.baidu.com/do/s? WORD = Baidu & Ct = 21 ");

Decode Using decodeuri ();

C #:Decodeuricomponent

 

3.

JS:Encodeuricomponent:

  • You must use encodeuricomponent when passing parameters so that the combined URL will not be truncated by special characters such.
  • Example: <script language = "JavaScript"> document. Write ('<a href = "http://passport.baidu.com /? Logout & Aid = 7 & U = '+ encodeuricomponent ("http://cang.baidu.com/bruce42") +' "> exit </a & gt; '); </SCRIPT>

Decode Using decodeuricomponent ()

C #:

[Httpcontext. Current.] server. urldecode

[Httpcontext. Current.] server. urlencode

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.