Some interesting questions about garbled Chinese characters when uploading values through URLs on the Asp.net page ~~~

Source: Internet
Author: User

Will garbled characters appear when the value is passed in Chinese? When and when? Have you ever thought about it? How can we avoid garbled characters ???

Recently, a live TV website was developed. In order to reduce the number of database queries, some Chinese characters must use the URL-based value transfer method. As a result, nothing happened. At that time, garbled characters were generated after the value was passed. Therefore, we suspect that the encoding is incorrect. Therefore, we need to add the egg statement <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/>. As a result, a miracle occurred, and the garbled characters finally disappeared. But it happened again. I clicked a few pages and garbled characters. Dizzy ~~

It is not related to encoding. But why didn't I try garbled characters? Well, I observed it and found an interesting problem,In the past, when a Chinese character passes a value through a URL to the same page, there will be no garbled characters; when it is passed to other pages, there will be garbled characters., Dizzy ~~

The next thing is to solve the problem of not passing the garbled code to its own page. So I am a newbie who can't help Baidu. I found the encoding and decoding methods and directly foundCodePost it:

<A href = 'HTTP: // www.cnblogs.com/common/download.aspx? Url = <% # eval ("dfile_url") %> & filename = <% #Server. urlencode(Eval ("dfile_name") %>'

String filename =Server. urldecode(Request. querystring ["FILENAME"]. tostring ());

So I made the code that hurt me directly, and the strange thing happened again. During the operation, all errors occurred ,,,

Error: the overload method that best matches "system. Web. httpserverutility. urlencode (string)" has some invalid parameters. ThisIt's so bad, too,This eval ("dfile_name") is not of the string type.Ah. Changed to <% # server. urlencode (eval ("dfile_name ").Tostring() %>, The result passes successfully ~~ Garbled characters disappear. Happy ~~

But the most terrible thing happened. I forgot to add it in the background code.Server. urldecode,String filename = request. querystring ["FILENAME"]. tostring (). Why is it that he forgot to decode it ??? Is it a spiritual event, and so I feel likeServer. urldecodeIf the result is the same, there is a wooden error. ,

Click a breakpoint to check what is going on.Server. urldecodeIs it true or not.The results show that the data is indeed encrypted with a lot of garbled characters, but the variable assigned to the string type will be automatically decoded, that is, string filename = request. querystring ["FILENAME"]. tostring (); will automatically help you decode !!!! However, you 'd better addServer. urldecodeBetter.

In conclusion, the questions answered by the so-called experts on the Internet are not necessarily correct. Some interesting things will be discovered by you inadvertently, which is unknown to others.

 

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.