Asp. The solution of Request.Form Chinese garbled in net

Source: Internet
Author: User
Tags object config copy net response code
Background

Involving two web sites of communication, site A has a page a, in the form of submission, the value of the site B to the page B. Website A unifies the UTF-8 code, the website B unifies uses the GB2312 code.

encoding settings in web.config
Website a:<globalization requestencoding= "UTF-8" responseencoding= "UTF-8"/>
Website b:<globalization requestencoding= "gb2312" responseencoding= "gb2312"/>
Solve

The results of online search, nothing more than to modify the Web.config file requestencoding, responseencoding and so on, which for me, is a pure idea. Plus the network crazy copy, paste, not verify the feasibility of the behavior, has been made me heinous, directly lead to search results are uniform, found is that several articles, the most angry is that the content is still wrong. So I have always insisted that the problems encountered, it is true that the feasibility of the blog posted in order to avoid misleading mistake himself. (hopefully not too far)

That's your own brain, a little comb, in fact, this process is very simple, is a UTF-8 page to send data to the GB2312 page, because the code is different, the appearance of garbled is normal, the solution is naturally unified coding.

The encoding of a Web page is the encoding of the receiving request data (requestencoding), and the first is the encoding of the sending response (responseencoding). As long as the page A to send a response to the Code, b page to receive the requested code consistent, you can solve the garbled problem.

Code only one sentence, in a page Page_Load method to add response.contentencoding = encoding.getencoding ("gb2312"); Can.
Copy CodeThe code is as follows:
Set a page response encoding to gb2312 to ensure the same code as the B page receives the request
protected void Page_Load (object sender, EventArgs e)
{
response.contentencoding = encoding.getencoding ("gb2312");
}

You may have an opinion, said, in turn set the B-page to receive the requested encoding and a page to send a response to the same, OK? I tried, no, see the code, if you know the principle, please inform, appreciate!
Copy CodeThe code is as follows:
Set B page to receive the request encoding for UTF-8, to ensure that a page response code consistent with, but not workable, why??
protected void Page_Load (object sender, EventArgs e)
{
request.contentencoding = encoding.getencoding ("Utf-8");
}


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.