Removes the specified parameter from URL to implement the C code

  • 2020-05-30 19:49:01
  • OfStack

 
#region URL Removes the specified parameter from  
/// <summary> 
///  Removes the specified parameter from  
/// </summary> 
/// <param name="url"> address </param> 
/// <param name="param"> parameter </param> 
/// <returns></returns> 
public static string buildurl(string url, string param) 
{ 
string url1 = url; 
if (url.IndexOf(param) > 0) 
{ 
if (url.IndexOf("&", url.IndexOf(param) + param.Length) > 0) 
{ 
url1 = url.Substring(0, url.IndexOf(param) - 1) + url.Substring(url.IndexOf("&", url.IndexOf(param) + param.Length) + 1); 
} 
else 
{ 
url1 = url.Substring(0, url.IndexOf(param) - 1); 
} 
return url1; 
} 
else 
{ 
return url1; 
} 
} 
#endregion 
#region " Access to the page url" 
/// <summary> 
///  Gets the currently visited page address parameter  
/// </summary> 
public static string GetScriptNameQueryString 
{ 
get 
{ 
return HttpContext.Current.Request.ServerVariables["QUERY_STRING"].ToString(); 
} 
} 
/// <summary> 
///  Gets the address of the currently accessed page  
/// </summary> 
public static string GetScriptName 
{ 
get 
{ 
return HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString(); 
} 
} 
/// <summary> 
///  Gets the currently accessed page Url 
/// </summary> 
public static string GetScriptUrl 
{ 
get 
{ 
return GetScriptNameQueryString == "" ? GetScriptName : string.Format("{0}?{1}", GetScriptName, GetScriptNameQueryString); 
} 
} 
/// <summary> 
///  Gets the currently accessed page   parameter  
/// </summary> 
public static string GetScriptNameQuery 
{ 
get 
{ 
return HttpContext.Current.Request.Url.Query; 
} 
} 
#endregion 

To remove more than one parameter, use it this way. buildurl (buildurl (buildurl (url, param1), param2), param3)

Related articles: