现在有大量的url网址,但其中很多url中都包含有汉字,
请问如何使用urlEncode只对其中的汉字进行编码????????????

解决方案 »

  1.   

    web.config
    <globalization....
    requestEncoding="GB2312"
    responseEncoding="GB2312"
    fileEncoding="GB2312"
      

  2.   

    用Server.HtmlEncode 或者HtmlDecode 编码或解码URL路径中的字符
      

  3.   

    /// <summary>
    /// 返囬編碼后的URL,解決.Net的URL編碼的錯誤
    /// </summary>
    /// <param name="strUrl">來源URL字符串</param>
    /// <returns>經過編碼后的字符串</returns>
    public static string GetUrlCode(string strUrl)
    {
    int N = strUrl.IndexOf("?")+1;
    if(N>0)
    {
    string strQuery = strUrl.Substring(N,strUrl.Length - N);
    string strUrls = strUrl.Substring(0,N);
    string[] strQ = strQuery.Split('&');
    System.Text.StringBuilder strT = new System.Text.StringBuilder();
    strT.Append(strUrls);
    for(int i=0;i<strQ.Length;i++)
    {
    string[] strQName = strQ[i].Split('=');
    string strQV = strQName[0] + "=" + System.Web.HttpContext.Current.Server.UrlEncode(System.Web.HttpContext.Current.Server.UrlDecode(strQName[1])); if(i==0)
    {
    strT.Append(strQV);
    }
    else
    { strT.Append("&" + strQV);
    }
    }
    return strT.ToString();
    }
    else
    {
    return strUrl;
    } }
      

  4.   

    难道一定要一个一个的找出其中的汉字,然后再对其进行编码? 
    有没有简单一点的方法?
    ---------------------------
    你不会对它们全部进行编码?这样不会有影响的,因为接收的时候,使用urlDecode就可以全部复原了。
      

  5.   

    用escapse编码,然后在后台解码吧
      

  6.   

    同意  hchxxzx(NET?摸到一点门槛) 所说的.
      

  7.   

    <A href='news.aspx?newstype=<%=Server.UrlEncode("新闻")%>'>新闻</A>
      

  8.   

    编码 Server.UrlEncode
    解码 Server.UrlDecode
    想编码什么,编码什么;
    想解码什么,解码什么。
    为什么非要汉字?