net 地址栏传中文的解决方法或地址栏传参数带中文的解决办法

1.传递中文之前,将要传递的中文参数进行编码,在接收时再进行解码。

>> 进行传递

string Name = "中文参数";

Response.Redirect("B.aspx?Name="+Server.UrlEncode(Name));

>> 进行接收

string Name = Request.QueryString["Name"];

Response.Write(Server.UrlDecode(Name));

或者:

NavigateURL='<%# "WebForm2.aspx?Singer=" + HttpUtility.UrlEncode("重庆", System.Text.Encoding.GetEncoding("GB2312")) %>'

2.如果是从 .HTML 文件向 .Aspx 文件进行传递中文参数的话(即不从后台用 Redirect()方法进行 Url 转换)。一样要将传递的中文参数进行编码,在接收时再进行解码。

>> 进行传递

<script language="JavaScript">

function GoUrl()

{

var Name = "中文参数";

location.href = "B.aspx?Name="+escape(Name);

}

</script>

<body onclick="GoUrl()">

>> 进行接收

string Name = Request.QueryString["Name"];

Response.Write(Server.UrlDecode(Name));

posted @ 2013-01-14 14:55  沅江  阅读(289)  评论(0编辑  收藏  举报