Remove the specified parameter from the URL to implement C # code

Source: Internet
Author: User
Tags servervariables

Copy codeThe Code is as follows:
# Remove the specified parameter from the region URL
/// <Summary>
/// Remove the specified parameter
/// </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 "retrieve page url"
/// <Summary>
/// Obtain the parameters of the current access page address
/// </Summary>
Public static string GetScriptNameQueryString
{
Get
{
Return HttpContext. Current. Request. ServerVariables ["QUERY_STRING"]. ToString ();
}
}
/// <Summary>
/// Obtain the address of the current access page
/// </Summary>
Public static string GetScriptName
{
Get
{
Return HttpContext. Current. Request. ServerVariables ["SCRIPT_NAME"]. ToString ();
}
}
/// <Summary>
/// Obtain the Url of the current access page
/// </Summary>
Public static string GetScriptUrl
{
Get
{
Return GetScriptNameQueryString = ""? GetScriptName: string. Format ("{0 }? {1} ", GetScriptName, GetScriptNameQueryString );
}
}
/// <Summary>
/// Obtain the parameters of the current access page
/// </Summary>
Public static string GetScriptNameQuery
{
Get
{
Return HttpContext. Current. Request. Url. Query;
}
}
# Endregion

Remove multiple parameters. 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.