我的webconfig里有这么一句
<globalization requestEncoding="iso-8859-1" responseEncoding="iso-8859-1"/>
这个我没法更改,整个项目的问题现在别人传给我一个querysting,是用urlencode过得 myname=%E9%98%BF%E5%AB%82%E5%A4%A7 本身是utf-8的编码字
但是我直接在代码 用 string xx= Request.QueryString["myname"];获取,单步调试直接出来就是乱码我查了下。net string 是unicode类型的,还不是utf-8
我想请教我下,我在这个页面里应该需要做些什么设置,如何接收转化才能得到不是乱码的。net字符串谢谢

解决方案 »

  1.   

    既然是urlencode过的字符串,你就需要
    HttpServerUtility.UrlDecode(xx)才能得到你要的字符串。
      

  2.   

    怎么弄。我先string myname= Request.QueryString["myname"]
    再再用HttpServerUtility.UrlDecode(myname)的值?
      

  3.   

    也可以用HttpUtility.UrlDecode,它支持在参数中指定Encoding
      

  4.   

    我这里的问题是页面设定的相应编码和字符串编码不同,
    比如你来源字符串是utf-8,相应的编码是iso-8859-1 结果就是服务器永远去按照 iso的编码去读utf-8的字符串,永远无解。在global。axac里加上如下代码即可
    也结贴吧protected void Application_BeginRequest(Object sender, EventArgs e)
    {
                string url = Request.Url.ToString();
                if (url.Contains("your page name"))
                {
                    Request.ContentEncoding= Encoding.GetEncoding("utf-8");
                    Response.ContentEncoding = Encoding.GetEncoding("utf-8");
                }
    }