我在web.config文件中使用的utf-8编码;
在Application_BeginRequest中处理url重写:
string oldUrl = HttpContext.Current.Request.RawUrl;
这样得到的url中如果有汉字是乱码的;使用以下代码进行转换的话:
                byte[] bytes = System.Web.HttpUtility.UrlDecodeToBytes(newUrl, Encoding.Default);
                string s = Encoding.Default.GetString(bytes);
                this.Context.RewritePath(s);
则在地址栏中输入带中文的地址,可以正常转换。但是在写在页面中的地址点击后还是出现乱码(该文件使用的utf-8保存的);
求解答;

解决方案 »

  1.   

    浏览器用的firefox和ie都试过,都不成。浏览器编码是unicode(utf-8)在地址栏中输入**?联想 能够正常解析出来。
    但将这个链接写到页面中,再点击 跳转的就是乱码了
      

  2.   

    form提交方式 强制 post 试下
      

  3.   

    中文,使用编码如
    HttpUtility.UrlDecode("")
    HttpUtility.UrlEncode("联想")
    excape等
      

  4.   

            
    HttpUtility.UrlEncode(str, Encoding.UTF8);
    HttpUtility.UrlDecode(str, Encoding.UTF8);
    如果是js跳转的话用encodeURIComponent编码下
      

  5.   

    我想知道 为什么我在地址栏中输入 www.a.com?a=联想 就可以,而将这个链接写到页面中<a href=" www.a.com?a=联想"></a> 再点击就是乱码?????????????以下方式也不行
                    string newUrl = Regex.Replace(oldUrl, pattern, replace, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    byte[] bytes = System.Web.HttpUtility.UrlDecodeToBytes(newUrl, Encoding.Unicode);
                    string s = Encoding.UTF8.GetString(bytes);
                    this.Context.RewritePath(s);
      

  6.   

    楼主这个问题我遇到过,是编码和解码的问题
    <a href='.aspx?FlowerName=<%# Server.UrlEncode(Eval("FlowerName").ToString()) %>' 我是在前面加上Sever.UrlEncode可以解决你可以试下