If you want to set page encoding for the entire project, you can add a Globalization attribute to the Web. config file and set its fileEncoding, requestEncoding, and responseEncoding features:
<Configuration>
<System. web>
<Globalization
FileEncoding = "UTF-8"
RequestEncoding = "UTF-8"
ResponseEncoding = "UTF-8"
Culture = "en-US"
UiCulture = "de-DE"
/>
</System. web>
</Configuration>
If you want to set encoding for a separate Page, you can set the RequestEncoding and ResponseEncoding features of the @ Page command:
<% @ Page RequestEncoding = "UTF-8" ResponseEncoding = "UTF-8" %>
Sometimes we have set the encoding of the entire site to gb2312 in the configuration file, but a page needs to use UTF-8. In this case, we can add a location node in the configuration file section:
Program code
<Location path = "Test. aspx">
<System. web>
<Globalization fileEncoding = "UTF-8" requestEncoding = "UTF-8" responseEncoding = "UTF-8" culture = "en"/>
</System. web>
</Location>
If you want to set a page to gb2312 separately, it is:
Program code <location path = "Test. aspx">
<System. web>
<Globalization fileEncoding = "gb2312" requestEncoding = "gb2312" responseEncoding = "gb2312" culture = "zh-CN"/>
</System. web>
</Location>
The following is a reference for some netizens to solve the problem:
When I used ASP. NET to write the online payment interface program, I encountered a strange problem. All the Chinese characters submitted through the form were garbled and the English language was normal. For testing with asp, you can submit Chinese characters normally. The asp page contains the following HTML code:
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
However, adding this code to the ASP. NET page still cannot solve the problem. After analysis, the problem should be caused by encoding. The program of the other party can only process the Chinese data submitted by the GB2312 encoding page. Is ASP. NET not displayed in GB2312 encoding after the above Code is added? Open the page, check the browser code, the original is UTF-8, the reason to find, how to solve it? It seems that ASP. NET ignores the above Code and sends the encoding information to the browser. Then I will try setting Response. ContentEncoding and add the following code in Page_Load:
Response. ContentEncoding = System. Text. Encoding. GetEncoding ("GB2312 ");
OK! Solve the problem!