搜索显示列表,用了URL参数传递搜索关键字,中文时碰到问题。
我已将参数中中文UrlEncode处理,但是分页后,页码的URL又把中文给Decode了,所以分页就出错了。
下面是搜索“王”后,页码中没有用UrlEncode处理过的字符串。。
<a title="转到第2页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=2">[2]</a><span style="width:6px;"></span><a title="转到第3页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=3">[3]</a><span style="width:6px;"></span><a title="转到第4页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=4">[4]</a><span style="width:6px;"></span><a title="转到第5页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=5">[5]</a><span style="width:6px;"></span><a title="转到第6页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=6">[6]</a><span style="width:6px;"></span><a title="转到第7页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=7">[7]</a><span style="width:6px;"></span><a title="转到第8页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=8">[8]</a><span style="width:6px;"></span><a title="转到第9页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=9">[9]</a><span style="width:6px;"></span>
<a title="转到第2页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=2">[2]</a><span style="width:6px;"></span><a title="转到第3页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=3">[3]</a><span style="width:6px;"></span><a title="转到第4页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=4">[4]</a><span style="width:6px;"></span><a title="转到第5页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=5">[5]</a><span style="width:6px;"></span><a title="转到第6页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=6">[6]</a><span style="width:6px;"></span><a title="转到第7页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=7">[7]</a><span style="width:6px;"></span><a title="转到第8页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=8">[8]</a><span style="width:6px;"></span><a title="转到第9页" href="/XJWebUI/Student/BasicInfo/StudentList.aspx?operation=王&amp;page=9">[9]</a><span style="width:6px;"></span>

解决方案 »

  1.   

    在 http://www.webdiyer.com/guestbook/default.aspx?page=6 发现一篇一样的问题。
       
    现在的url实现方式有一个bug,如果原来的url中已经有参数,并且参数中有中文(已经UrlEncode过了),这样,分页后,页码中的url又把中文还原了。这样就会出问题。我尝试着修改了以下这段代码,但老是报错:“非静态的字段、方法或属性“System.Web.HttpServerUtility.UrlEncode(string)”要求对象引用”,所以想请老师帮忙修改,谢谢。 -------------------------------------------------------------------------- protected override void OnLoad(EventArgs e) { if(urlPaging) { currentUrl=Page.Request.Path; ////Modifyed By HunterGu currentUrl = HttpServerUtility.UrlEncode(currentUrl); ///////////////////////// urlParams=Page.Request.QueryString; string pageIndex=Page.Request.QueryString[urlPageIndexName]; int index=1; try { index=int.Parse(pageIndex); } catch{} OnPageChanged(new PageChangedEventArgs(index)); } else { inputPageIndex=Page.Request.Form[this.UniqueID+"_input"]; } base.OnLoad(e); }
    --------------------------------------------------------------------------------
    版主回复:您好,这个是以前版本的问题,新版中已经解决了,请从这里下载最新的4.3.5版。谢谢!  但是我下了4.3.5版的,问题还是没解决,希望吴旗娃老师能帮忙解决,谢谢
      

  2.   

    刚改成这样,好像可以了。
    本来是UTF-8的。
    <globalization requestEncoding="GB2312" responseEncoding="GB2312"
       fileEncoding="GB2312" />
    但是这样URL中还是存在中文,不知道会不会对其他的地方有影响。。
      

  3.   

    自己修改下源代码吧,这样改:
            private string BuildUrlString(NameValueCollection col)
            {
                int num1;
                string text1 = "";
                if ((this.urlParams == null) || (this.urlParams.Count <= 0))
                {
                    for (num1 = 0; num1 < col.Count; num1++)
                    {
                        text1 = text1 + ("&" + col.Keys[num1] + "=" + System.Web.HttpUtility.UrlEncode(col[num1]));
                    }
                    return (this.currentUrl + "?" + text1.Substring(1));
                }
                NameValueCollection collection1 = new NameValueCollection(this.urlParams);
                string[] textArray1 = collection1.AllKeys;
                num1 = 0;
                while (num1 < textArray1.Length)
                {
                    textArray1[num1] = textArray1[num1].ToLower();
                    num1++;
                }
                num1 = 0;
                while (num1 < col.Count)
                {
                    if (Array.IndexOf<string>(textArray1, col.Keys[num1].ToLower()) < 0)
                    {
                        collection1.Add(col.Keys[num1], col[num1]);
                    }
                    else
                    {
                        collection1[col.Keys[num1]] = col[num1];
                    }
                    num1++;
                }
                StringBuilder builder1 = new StringBuilder();
                for (num1 = 0; num1 < collection1.Count; num1++)
                {
                    builder1.Append("&");
                    builder1.Append(collection1.Keys[num1]);
                    builder1.Append("=");
                    builder1.Append(System.Web.HttpUtility.UrlEncode(collection1[num1]));
                }
                return (this.currentUrl + "?" + builder1.ToString().Substring(1));
            }
      

  4.   

    对不起,最近老是有做不完的活,没有多少时间来CSDN。
    我当初就是象楼上这样做的,可是发现不对,你可以试试翻到第二页,然后就能看到已经UrlEncode的字符又被UrlEncode了一次,变成了乱码,所以最后只好保留原状,就是现在版本这样,暂时没想到有什么好办法来解决这个问题,但只要用gb2312编码就不会出错。