ASP. NET: Form: A Summary of solutions for submitting Chinese garbled characters

Source: Internet
Author: User

From: http://xyztony1985.blog.163.com/blog/static/361178201081754921150/, thanks to the author's selfless dedication

Garbled information submitted by form,

 

Preface

I always thought that only request. when querystring receives a URL query string containing Chinese characters, it may be garbled (it is easy to avoid coding and decoding). When it comes to the request, it will be known. the value of the form received by form may contain Chinese characters. It was silly, naive, and ignorant.

Background

When communication between two websites is involved, website A has a page A, which is passed to page B of website B by submitting a form. Website a unified with UTF-8 encoding, website B unified with gb2312 encoding.
Encoding settings in Web. config

Website A: <globalization requestencoding = "UTF-8" responseencoding = "UTF-8"/>
Website B: <globalization requestencoding = "gb2312" responseencoding = "gb2312"/>

Solution

The online search results are nothing more than modifying the requestencoding and responseencoding of the web. config file, which is purely an idea for me. In addition, the network's crazy copying, pasting, unverified feasibility and other behaviors have always led me to continue, which directly led to the same search results and found several articles, the most angry part is whether the content is correct. Therefore, I have always insisted that the problems I encountered are verified to be feasible, so that I can post them on my blog to avoid mistakes. (Hope it's not too far)

That is their own brains, a little combing, in fact, this process is very simple, is a UTF-8 page to send data to the gb2312 page, because of the different encoding, garbled normal, the solution is unified encoding.

The encoding of the webpage. One is the requestencoding and the other is the responseencoding. As long as the encoding of the response sent by page a is consistent with the encoding of the requests received by page B, the garbled problem can be solved.

The Code contains only one sentence. Add response. contentencoding = encoding. getencoding ("gb2312"); To the page_load Method on page.
// Set the response code of page a to gb2312 to ensure that it is consistent with the encoding of the request received by page B.
Protected void page_load (Object sender, eventargs E)
{
Response. contentencoding = encoding. getencoding ("gb2312 ");
}

You may have some comments, saying that, in turn, setting the encoding for receiving requests on page B is the same as that for sending responses on page. I have tried it. No, see the code. If you know the principle, please let me know. Thank you very much!
// Set the UTF-8 encoding for receiving requests from page B to ensure that the encoding is consistent with the response code of page A, but does not work. Why ??
Protected void page_load (Object sender, eventargs E)
{
Request. contentencoding = encoding. getencoding ("UTF-8 ");
}

 

 

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.