Last active
August 29, 2015 14:15
-
-
Save sotirisf/3e3f5fbc9ed77eab3707 to your computer and use it in GitHub Desktop.
Updates a querystring parameter with a new value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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