当前位置: 首页 > 图文教程 > 网络编程 > 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="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)); |
一般来说。设置web.config文件就可以了。但是如果你用 JavaScript 调用 webservice 方法的话(往webservice里面传递中文参数)。设置 web.config 文件好象无效。
评论 (0) All