string InsertOrUpdateQueryStringItem(string key, string value)
{
if (Request.QueryString.HasKeys())
{
if (!Array.Exists<string>(Request.QueryString.AllKeys, (qs) => { return qs.Equals(key); }))
{
return string.Format("{0}&{1}={2}", Request.RawUrl, key, value);
}
else
{
System.Text.StringBuilder pathBuilder = new System.Text.StringBuilder(Request.Path);
pathBuilder.Append("?");
string keyValue;
string keyCurrent;
int handedCount = ;
foreach (var k in Request.QueryString.AllKeys)
{
if (!k.Equals(key))
{
keyValue = Request.QueryString[k];
keyCurrent = k;
}
else
{
keyValue = value;
keyCurrent = key;
}
if (string.IsNullOrEmpty(keyValue))
{
continue;
}
if (handedCount++ != )
{
pathBuilder.AppendFormat("&{0}={1}", keyCurrent, keyValue);
}
else
{
pathBuilder.AppendFormat("{0}={1}", keyCurrent, keyValue);
}
}
return pathBuilder.ToString();
}
}
return string.Format("{0}?{1}={2}", Request.Path, key, value);
}