重建URL参数
2015-12-05 09:23:35 访问(1944) 赞(0) 踩(0)
/// <summary>
/// 重建URL参数
/// </summary>
/// <param name="noContainsKey">keyOne|keyTwo|keyThree模式</param>
/// <returns></returns>
public static string RebuildQueryStringByParams
(
string noContainsKey
)
{
HttpRequest hr = HttpContext.Current.Request;
int iCount = hr.QueryString.Count;
if (iCount == 0)
return "";
string noContainsKeyText = "";
if (noContainsKey != null)
{
noContainsKey = noContainsKey.Trim();
if (noContainsKey.Length != 0)
{
noContainsKeyText =
new StringBuilder("|").Append(noContainsKey).Append("|").ToString().ToLower();
}
}
string sKey = null;
StringBuilder theResult = new StringBuilder();
if (noContainsKeyText.Length == 0)
{
sKey = hr.QueryString.Keys[0];
theResult.Append(sKey);
theResult.Append("=");
theResult.Append(hr.QueryString[sKey]);
for (int i = 1; i < iCount; ++i)
{
theResult.Append("&");
sKey = hr.QueryString.Keys[i];
theResult.Append(sKey);
theResult.Append("=");
theResult.Append(hr.QueryString[sKey]);
}
}
else
{
bool isFill = false;
StringBuilder sbKey = null;
for (int i = 0; i < iCount; ++i)
{
sKey = hr.QueryString.Keys[i];
sbKey = new StringBuilder();
sbKey.Append("|");
sbKey.Append(sKey.Trim().ToLower());
sbKey.Append("|");
if (noContainsKeyText.Contains(sbKey.ToString()))
continue;
if (isFill)
{
theResult.Append("&");
}
else
{
isFill = true;
}
theResult.Append(sKey);
theResult.Append("=");
theResult.Append(hr.QueryString[sKey]);
}
}
return theResult.ToString();
}
标签:
重建URL参数 


上一条:
下一条:
相关评论
发表评论