【www.gdgbn.com--中文酷站】

asp教程.net url传递中文乱码的解决方案

1.设置web.config文件。

......

......

2.传递中文之前,将要传递的中文参数进行编码,在接收时再进行解码。
>> 进行传递
string name = "中文参数";
response.redirect("b.aspx?name="+server.urlencode(name));
>> 进行接收
string name = request.querystring["name"];
response.write(server.urldecode(name));
3.如果是从 .html 文件向 .aspx 文件进行传递中文参数的话(即不从后台用 redirect()方法进行 url 转换)。一样要将传递的中文参数进行编码,在接收时再进行解码。
>> 进行传递
<script language="网页特效">
function gourl()
{
var name = "中文参数";
location.href = "b.aspx?name="+escape(name);
}
</script>

>> 进行接收
string name = request.querystring["name"];
response.write(server.urldecode(name));


实例方法

a项目中
        string url = "http://" + arr[2] + ":111/loginif.aspx?uid=" + server.urlencode(arr[0]) + "&pwd=" + arr[1];   //中文账号转码

        clientscript.registerclientscriptblock(this.gettype(), "this", "<script>window.open("" + url + "")</script>"); 这样传参数 uid传的是中文

b项目里接收 
 userloginif(server.urlencode(request["uid"].tostring()), request["pwd"].tostring());   //中文必须转码


指定编码
发送方 server.urlencode("中文", encoding.getencoding("gb2312"));
接收方 server.urldecode(request["key"], encoding.getencoding("gb2312"));


userloginif(server.urldecode(request["uid"].tostring()), request["pwd"].tostring());  


encode是编码,decode是解码.

如果还不行,
就使用post方式,或使用requestheader,或
考虑用webservice做proxy转发.

本文来源:http://www.gdgbn.com/kuzhan/26566/