问一个简单的问题哦, 有一个页面上有一个文本框和一个按钮,点击这个按钮后进入另一个页面,并且把文本框的值传给这个页面,怎么把传过去的值编码,就是说如果文本框的值是中文的话,传值的时候不显示中文
 
  比如说传过来以后的页页是:http://www.xxx.com/aa.aspx?keyWord=测试
 
  我现在要弄的是将传过来的值进行编码,也就是说在处理过以后页的地址是这样子的:
                     http://www.xxx.com/aa.aspx?keyWord=%E6%90%9C%E7%B4%A2
以前弄过不次, 不过忘了,高手们帮帮忙,谢谢了!

解决方案 »

  1.   

    HttpUtility.UrlEncode 方法: 对 URL 字符串进行编码,以便实现从 Web 服务器到客户端的可靠的 HTTP 传输。 重载列表 
    将字节数组转换为已编码的 URL 字符串,以便实现从 Web 服务器到客户端的可靠的 HTTP 传输。 
    [C#] public static string UrlEncode(byte[]); 对 URL 字符串进行编码,以便实现从 Web 服务器到客户端的可靠的 HTTP 传输。 
    [C#] public static string UrlEncode(string); 使用指定的编码对象对 URL 字符串进行编码,以便实现从 Web 服务器到客户端的可靠 HTTP 传输。 
    [C#] public static string UrlEncode(string, Encoding); 从数组中的指定位置开始一直到指定的字节数为止,将字节数组转换为 URL 编码的字符串,以便实现从 Web 服务器到客户端的可靠的 HTTP 传输。 
    [C#] public static string UrlEncode(byte[], int, int); HttpUtility.UrlDecode 方法: 将已经为在 URL 中传输而编码的字符串转换为解码的字符串。 重载列表 
    将已经为在 URL 中传输而编码的字符串转换为解码的字符串。 
    [C#] public static string UrlDecode(string); 使用指定的解码对象将 URL 编码的字节数组转换为已解码的字符串。 
    [C#] public static string UrlDecode(byte[], Encoding); 使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串。 
    [C#] public static string UrlDecode(string, Encoding); 使用指定的编码对象,从数组中的指定位置开始到指定的字节数为止,将 URL 编码的字节数组转换为已解码的字符串。 
    [C#] public static string UrlDecode(byte[], int, int, Encoding); 
      

  2.   


    Server.UrlEncode
    Server.UrlDecode
    具體可查看MSDN中關於HttpUtility的介紹。
      

  3.   

    编码就可以了,Server.UrlEncode编码,另外一个页面了Server.UrlDecode解码就ok了。
      

  4.   

    using System.Collections.Specialized;
    using System.Text;
    NameValueCollection gb2312Requests;
    gb2312Requests = HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding("GB2312"))
    Response.Redirect("a.aspx?ret="+gb2312Requests["string"]); //'string为提交的参数的Keyhttp://hi.baidu.com/zzticzh/blog/item/e2806c097bc21ec93ac763a0.html
    http://www.cnblogs.com/music000/archive/2009/03/03/1402645.html
    其它
      

  5.   

    Response.Redirect(string.Format("http://www.xxx.com/aa.aspx?keyWord={0}",Server.UrlEncode(TextBox1.Text)));
      

  6.   

    bytes=System.Text.Encoding.Unicode.GetBytes(str)   
    str=System.Text.Encoding.Unicode.GetString(bytes) 
      

  7.   

    如果这个:Server.UrlEncode 不行就用:HttpUtility.UrlEncode这个其实,我觉得如果可以,你完全不用传值这么明显,你可以用Cookie或者Session来记录传值,传过去用完清空一下(释放一下就行)这样还不用那么麻烦还可以让人看不出来,不是吗,这样还更安全些。不怕被人反编译后得到你不想让人看到的值。
      

  8.   

    URLEnCode  编码
    UrlDecode 解码
      

  9.   

    ---------一个简单的方法 ----------------------------
    写入时
     Response.Redirect("newsList.aspx?str=" + HttpUtility .UrlEncode (myid ,Encoding .GetEncoding ("GB2312")) + "");
    获得时
    NameValueCollection nv = HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding("GB2312"));            string proname = nv["ID"];
      

  10.   

    Server.UrlEncode
    Server.UrlDecode
      

  11.   

    服务端执行的话用
    Server.UrlEncode 
    Server.UrlDecode 客户端执行的话用
    escape
    unescape
    都可以实现你要的方法
      

  12.   

     HttpUtility.UrlEncode("")
     HttpUtility.UrlDecode("")
    js里用escape