日期:2014-05-18  浏览次数:20431 次

asp通过url传递中文到asp.net时乱码
asp:

Response.Redirect( "test.aspx?name= "   &   Server.URLEncode( "中文 "))


asp.net:

string   name   =   Request.QueryString[ "name "];
Response.Write(name);     //   乱码
Response.Write(Server.UrlDecode(name));     //   乱码
Response.Write(HttpUtility.UrlDecode(name,   Encoding.GetEncoding( "gb2312 ")));     //   乱码

上面的方法都会乱码,即使在 <@   Page> 设置ResponseEncoding= "gb2312 "或者CodePage= "936 "都会乱码,但是如果在web.config里设置:
<globalization   requestEncoding= "gb2312 "   /> 就显示正常。

但我不想为了这个问题再加多一个web.config文件。请问在aspx里面应该怎么做才能解决这个乱码问题?
谢谢!

------解决方案--------------------
zai web.config里设置是最好的。。如果你不想。你可以换成utf-8看看
保存的是也用这个

------解决方案--------------------
a页面:Response.Redirect(HttpUtility.UrlEncode(name));
b页面:Response.Write(HttpUtility.UrlDecode(Request.QueryString[ " "].ToSTRING()));
------解决方案--------------------
把参数换成utf-8....或者在webconfig里面设置成中文

------解决方案--------------------
既然编码要,接受的时候要解码啊~!

解码:HttpUtility.UrlDecode
------解决方案--------------------
string a = server.urlencode( "中国 ");编码。传递页面
string b = server.urldecode(request.querystring[ "a "]);接收页面 解码