页面间传输中文的乱码解决方法

2 views
Skip to first unread message

Wayn...@gmail.com

unread,
May 3, 2008, 11:06:04 PM5/3/08
to 就是怕忘了
今天测试昨天完成的页面,参数中用了中文,发现结果不对,有乱码。打开Web.config,发现.NET在Web.config中的默认编码格式为
utf-8,于是在传输中文的时候变成了乱码,相应的接收也是乱码,解决这个问题主要可以用两种方法。

第一种方法,是更改Web.config中的编码方式:
在你的web.config中把
<globalization requestEncoding="utf-8″ responseEncoding="utf-8″/>
改为<globalization requestEncoding="gb2312″ responseEncoding="gb2312″/>

第二种方法,在传递之前先编码,如:
string strName = Server.URLEncode("知识共享");
Response.Redirect("Manage.aspx?strTitle=" + strName);
然后在接收端用 Server.URLDecode(Request.QueryString["strTitle"]);

Wayn...@gmail.com

unread,
May 3, 2008, 11:20:07 PM5/3/08
to 就是怕忘了
参照web.config的设置
To specify encoding
To set the encoding for all pages, add a Globalization property to the
Web.config file, and then set its fileEncoding, requestEncoding, and
responseEncoding attributes, as shown in the following example:

Copy Code
<configuration>
<system.web>
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-US"
uiCulture="de-DE"
/>
</system.web>
</configuration>

To set the encoding for an individual page, set the RequestEncoding
and ResponseEncoding attributes of the @ Page directive, as shown in
the following example:

Copy Code
<%@ Page RequestEncoding="utf-8" ResponseEncoding="utf-8" %>

detail infomation:http://msdn.microsoft.com/en-us/library/39d1w2xf.aspx

Wayn...@gmail.com

unread,
May 3, 2008, 11:22:32 PM5/3/08
to 就是怕忘了
<globalization requestEncoding="utf-8" responseEncoding="utf-8"
culture="zh-CN" uiCulture="zh-CN"/>
Reply all
Reply to author
Forward
0 new messages