User36583972 posted
i want to remove first parameter from url how can i do it
Hi friend,
You may can try the following methods.
var stri= RemoveQueryStringByKey("https://www.google.co.uk/search?hl=en&output=search&sclient=psy-ab&removeparamter=cookie", "removeparamter");
public static string RemoveQueryStringByKey(string url, string key)
{
var uri = new Uri(url);
// this gets all the query string key value pairs as a collection
var newQueryString = HttpUtility.ParseQueryString(uri.Query);
// this removes the key if exists
newQueryString.Remove(key);
// this gets the page path from root without QueryString
string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path);
return newQueryString.Count > 0
? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
: pagePathWithoutQueryString;
}
If I have any misunderstanding, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages.
Best Regards,
Yong Lu