The Chinese characters are garbled during Intelligencia. UrlRewriter.

Source: Internet
Author: User

The Chinese characters are garbled during Intelligencia. UrlRewriter.

Due to business needs, some modules of the project have recently been modified to pseudo-static, and Intelligencia. UrlRewriter. dll components have been used.

Intelligencia. UrlRewriter. dll configuration on the Internet to explain a lot, here not to mention, (such as: http://www.cnblogs.com/naoguazi/p/URLReWriter.html)

This article mainly describes solutions to Garbled text when Url is passed.

1. At first, we used "cheap tricks" to solve the problem.

The idea is to encode Chinese characters when passing Chinese parameters through URLs. Jquery can use (encoding: encodeURIComponent (val); decoding: decodeURIComponent (val) for encoding and decoding. On the IISWeb server I use, the URL encoded parameter character is (% E8 % 9A % 82% E8 % 9A % 81% E7 % 94% B7 % E5 % AD % A9) an error is reported during transmission. Then I replace the percent sign (% E8 % 9A % 82% E8 % 9A % 81% E7 % 94% B7 % E5 % AD % A9 ") with a short underline ". replace (/%/gm ,'_')). Then, the string is transferred to the background and replaced, decoded, and then ......... The soldiers will block the attack, and the water will cover the earth. This is the case with cheap tricks. In the end, the Chinese parameters can be correctly passed into the background. Although this method solves the problem temporarily, it will leave a pain point for future friends.

 

2. Modify the source code and re-compile Intelligencia. UrlRewriter. dll. Make the component support passing Chinese parameters.

Find the source code on GitHub and download it. Https://github.com/OptimityAdvisors/Intelligencia.UrlRewriter)

Open the solution and insert the code into the RewriterEngine. cs file private string Reduce (RewriteContext context, StringReader reader) method.

result = string.Join("&", result.Split('&').Select(e => string.Join("=", e.Split('=').Select(o => HttpContext.Current.Server.UrlEncode(o)))));

 

After saving the compiled dll, it will support passing Chinese characters,

 

Note that parameters received in the background are decoded before use.

var str= HttpContext.Current.Server.UrlDecode(str);

 

 

Dll that supports Chinese parameters: Download

 

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.