URL to remove the specified parameters to implement C # code-Practical Tips

Source: Internet
Author: User
Tags httpcontext servervariables
Copy Code code as follows:

Remove the specified parameter #region URL
<summary>
To remove the specified parameter
</summary>
<param name= "url" > Address </param>
<param name= "param" > Parameters </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 "Get page URL"
<summary>
Get the current access page address parameter
</summary>
public static string getscriptnamequerystring
{
Get
{
return httpcontext.current.request.servervariables["Query_string"]. ToString ();
}
}
<summary>
Get the current access page address
</summary>
public static string Getscriptname
{
Get
{
return httpcontext.current.request.servervariables["Script_name"]. ToString ();
}
}
<summary>
Get the current access page URL
</summary>
public static string Getscripturl
{
Get
{
return getscriptnamequerystring = = ""? Getscriptname:string. Format ("{0}?{ 1} ", Getscriptname, getscriptnamequerystring);
}
}
<summary>
Get current access page parameters
</summary>
public static string Getscriptnamequery
{
Get
{
return HttpContext.Current.Request.Url.Query;
}
}
#endregion

To get rid of multiple parameters, use it. BuildUrl (BuildUrl (BuildUrl (url,param1), param2), param3)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.