System Information

Impossible Is Nothing...

导航

URL Encoding/Decoding

论坛中经常会看到有人问,在URL传递中文时会出现传递不全的情况,解决方案如下:
修改web.config文件中的utf-8改为gb2312
然后传递的时候这样写:
url="description.aspx?name="+Server.UrlEncode(myname.text)
response.redirect(url)

接收的时候:
name=Server.UrlDecode(Request.QueryString("name"))

//按照UTF-8进行编码
string tempSearchString1 = System.Web.HttpUtility.UrlEncode("C#中国");
//按照GB2312进行编码
string tempSearchString2 = System.Web.HttpUtility.UrlEncode("C#中国",System.Text.Encoding.GetEncoding("GB2312"));


另外给二个说明及案例地址:
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemwebhttpserverutilityclassurlencodetopic1.asp

http://dotnet.aspx.cc/ShowDetail.aspx?id=YUEMA9OS-W1DN-4KIS-8RIE-S742LLJ91L6Q

posted on 2005-06-09 16:32  SysInfo  阅读(2533)  评论(0编辑  收藏  举报