您的位置:首页 > 编程语言 > ASP

ASP.NET中文乱码问题

2011-07-29 15:38 363 查看
 解决ASP.NET中文乱码的方法一般有3种:
1.设置web.config:
< system.web>    
< globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312" />   
< /system.web>

2.前台编码,后台解码:

    前台编码:

function GoUrl()   
{   
var Name = "中文参数";   
location.href = "B.aspx?Name="+escape(Name) ;   
}

    后台解码:
string Name = Server.UrlDecode(Request.QueryString["Name"]);

3.Response.Redirect("test1.aspx?111="+System.Web.HttpUtility.UrlEncode("中华人明共和国")) ;   
//建议使用最后如果是从其他的页面获取中文参数没有乱码,那就更简单了   
string message ="http://localhost/Test/test1.aspx?111="+System.Web.HttpUtility.UrlEncode("中华人明共和国");   
http:  
//你要获取某个页面的返回值的地址"  
//发送请求  
 HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(message) ;  
//接受请求  
 HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse() ;  
 Stream receiveStream = myHttpWebResponse.GetResponseStream() ;  
 StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.GetEncoding("GB2312")) ;  
//此为要取页面的返回值输出的返回结果  
 returnValue = readStream.ReadToEnd();  
 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息