/// <summary>
/// 移除Url中的参数
/// </summary>
/// <param name="url">原始url</param>
/// <param name="parameters">需要移除的参数</param>
/// <returns>移除了参数的Url</returns>
private string RemoveUrlParameters(string url , params string[] parameters)
{
string cleanUrl = string.Empty;
string parasString = string.Empty;
string[] urlArray = new string[]{};
string resultUrl = string.Empty;
//将原始Url以“?”“&”分解成字符串数组(因为参数是以此二符号作为分隔符的)
if (url != string.Empty)
{
urlArray = url.ToLower().Split(new string[] { "?","&" }, StringSplitOptions.RemoveEmptyEntries);
}
//其中数组的第一个元素是无任何参数的Url
cleanUrl = urlArray[0];
resultUrl += cleanUrl;
//数组的维数
int countUrlArray = urlArray.Length;
//由于用于隔离参数和Url之间需要使用“?”,而参数之间的分隔则使用"&",而且只有第一次的时候是用“?”
int addTimes = 0;
//判断所有要移除的参数和现有Url字符串数组之间的关系,
//如果当前遍历到的Url字符串
foreach (string para in parameters)
{
for(int i =1;i<countUrlArray ;i++)
{
if (!ParameterContains(urlArray[i],para))
{
if (addTimes == 0)
{
resultUrl = resultUrl + "?" + urlArray[i];
}
else
{
resultUrl = resultUrl + "&" + urlArray[i];
}
addTimes++;
}
}
}
return resultUrl;
}
/// <summary>
/// 判断形如“abcdefg=1234567”的字符串等号左侧是否是参数parameter,是则返回true,否则返回false
/// </summary>
/// <param name="paraString">形如“abcdefg=1234567”的字符串</param>
/// <param name="parameter"></param>
/// <returns></returns>
private bool ParameterContains(string paraString, string parameter)
{
bool isContain = false;
if(paraString!=string.Empty)
{
string[] paraKey = paraString.Trim().Split(new char[] { '=' });
if (paraKey[0] == parameter)
isContain = true;
}
return isContain;
}
/// <summary>
/// 移除Url中的全部参数
/// </summary>
/// <param name="url">原始Url</param>
/// <returns></returns>
private string RemoveUrlParameters(string url)
{
string cleanUrl = string.Empty;
if (url != string.Empty)
{
string[] urlArray = url.ToLower().Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries);
cleanUrl = urlArray[0];
}
return cleanUrl;
}
/// 移除Url中的参数
/// </summary>
/// <param name="url">原始url</param>
/// <param name="parameters">需要移除的参数</param>
/// <returns>移除了参数的Url</returns>
private string RemoveUrlParameters(string url , params string[] parameters)
{
string cleanUrl = string.Empty;
string parasString = string.Empty;
string[] urlArray = new string[]{};
string resultUrl = string.Empty;
//将原始Url以“?”“&”分解成字符串数组(因为参数是以此二符号作为分隔符的)
if (url != string.Empty)
{
urlArray = url.ToLower().Split(new string[] { "?","&" }, StringSplitOptions.RemoveEmptyEntries);
}
//其中数组的第一个元素是无任何参数的Url
cleanUrl = urlArray[0];
resultUrl += cleanUrl;
//数组的维数
int countUrlArray = urlArray.Length;
//由于用于隔离参数和Url之间需要使用“?”,而参数之间的分隔则使用"&",而且只有第一次的时候是用“?”
int addTimes = 0;
//判断所有要移除的参数和现有Url字符串数组之间的关系,
//如果当前遍历到的Url字符串
foreach (string para in parameters)
{
for(int i =1;i<countUrlArray ;i++)
{
if (!ParameterContains(urlArray[i],para))
{
if (addTimes == 0)
{
resultUrl = resultUrl + "?" + urlArray[i];
}
else
{
resultUrl = resultUrl + "&" + urlArray[i];
}
addTimes++;
}
}
}
return resultUrl;
}
/// <summary>
/// 判断形如“abcdefg=1234567”的字符串等号左侧是否是参数parameter,是则返回true,否则返回false
/// </summary>
/// <param name="paraString">形如“abcdefg=1234567”的字符串</param>
/// <param name="parameter"></param>
/// <returns></returns>
private bool ParameterContains(string paraString, string parameter)
{
bool isContain = false;
if(paraString!=string.Empty)
{
string[] paraKey = paraString.Trim().Split(new char[] { '=' });
if (paraKey[0] == parameter)
isContain = true;
}
return isContain;
}
/// <summary>
/// 移除Url中的全部参数
/// </summary>
/// <param name="url">原始Url</param>
/// <returns></returns>
private string RemoveUrlParameters(string url)
{
string cleanUrl = string.Empty;
if (url != string.Empty)
{
string[] urlArray = url.ToLower().Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries);
cleanUrl = urlArray[0];
}
return cleanUrl;
}