Skip to content

Instantly share code, notes, and snippets.

@sotirisf
Last active August 29, 2015 14:15
Show Gist options
  • Save sotirisf/3e3f5fbc9ed77eab3707 to your computer and use it in GitHub Desktop.
Save sotirisf/3e3f5fbc9ed77eab3707 to your computer and use it in GitHub Desktop.
Updates a querystring parameter with a new value
/// <summary>
/// Updates a querystring parameter with a new value
/// </summary>
/// <param name="req">The HTTPRequest object</param>
/// <param name="parameterName">The parameter name to update</param>
/// <param name="parameterValue">The new value for the parameter</param>
/// <returns></returns>
public static string UpdateQueryString(HttpRequest req, string parameterName, string parameterValue)
{
var nameValues = HttpUtility.ParseQueryString(req.QueryString.ToString());
nameValues[parameterName] = parameterValue;
string url = req.Url.AbsolutePath;
string updatedQueryString = "?" + nameValues.ToString();
return (url + updatedQueryString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment