这两个函数都是相对当前的请求的URL来处理的。
例如:http://baidu.com/?a=hello&b=world
添加函数输入:("c","kkcat"),输出就是http://baidu.com/?a=hello&b=world&c=kkcat
删除函数输入:("b"),输出就是http://baidu.com/?a=hello
 value)
    {
        return QueryParameter(new Dictionary<stringstring>() { { key, value } },string.Empty);
    }

    
public static string QueryParameter(string key, string value, string path)
    {
        
return QueryParameter(new Dictionary<stringstring>() { { key, value } }, path);
    }

    
public static string QueryParameter(Dictionary <string,string> dics,string path)
    {
        
string ret=string.Empty ;
        Dictionary
<stringstring> OldQueryString = new Dictionary<stringstring>();

        
foreach (string key in Page.Request.QueryString.AllKeys)
        {
             OldQueryString .Add (key,Page.Request .QueryString [key]);
        }

        
foreach (KeyValuePair <string,string> item in dics)
        {
            
if (!OldQueryString.ContainsKey(item.Key))
                OldQueryString.Add(item.Key, item.Value);
            
else
                OldQueryString[item.Key] 
= item.Value;
        }

        
foreach (KeyValuePair<stringstring> item in OldQueryString)
        {
            ret 
+= string.Format("{0}={1}&", item.Key, item.Value);
        }

        
if(ret.EndsWith ("&"))
            ret
=ret.Substring (0,ret.Length -1);

        
if (string.IsNullOrEmpty(path))
            path 
= Page.Request.Path;

        
return Utils.ToUri ( path).ToString () +"?"+ret;
    }
 ret;
        }
    }

相关文章: