Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with the phenomenon of Chinese garbled code when static gb2312 code transmits values in the project?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "static gb2312 coding in the project value in the Chinese garbled phenomenon how to do", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "static gb2312 coding in the project value of Chinese garbled phenomenon how to do" this article.

Maybe the title description is not very clear.

The problem at that time is like this: in my system project, the reference art static page is in gb2312 format. When this code is obtained in the project, the utf-8-coded system will have style problems when loading the page, such as not being in the middle normally. (IE6 usually has style problems)

The solution is as follows (if gb2312 coding is necessary)

Add in webconfig

The copy code is as follows:

At this point, the page effect is normal.

However, if you encounter the function of transmitting values in Chinese on the page at this time, the Chinese characters of the values will be garbled. Even if encodeURIComponent is used in js, it can't be solved.

At this point, the following class is added to the project to specifically handle the transfer of request values back to utf-8 format.

The copy code is as follows:

Namespace XXX

{

/ / used to deal with the problem that UTF-8 can not get the style under IE6: change the encoding of web to gb2312,request and transfer the value back to utf-8 by this method

Public class ContentEncodingModule: IHttpModule

{

Public void Init (HttpApplication app)

{

App.BeginRequest + = new EventHandler (app_BeginRequest)

}

Public void Dispose ()

{

}

Void app_BeginRequest (object sender, EventArgs e)

{

HttpApplication app = (HttpApplication) sender

HttpWorkerRequest request = ((IServiceProvider) app.Context)

.GetService (typeof (HttpWorkerRequest)) as HttpWorkerRequest)

App.Request.ContentEncoding = System.Text.Encoding.UTF8

}

}

}

And reference this class in webconfig

Problem solved.

However, according to the reference article, try not to encode static pages in gb2312 unless there is a special purpose.

The above is "static gb2312 code in the project value in the Chinese garbled phenomenon how to do" all the content of this article, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report