replace values in the QueryString key/value pairs

October 14, 2009


The URL with a  QueryString is something like “apage.aspx?month=10&year=2006&…”, anything in Request.QueryString cannot be changed because it is readonly, but the values of “month” and “year” can be changed as followed:

NameValueCollection nvc = HttpUtility.ParseQueryString(Request.QueryString.ToString());

nvc.Set(“month”, “12″);

nvc.Set(“year”, “2009″);

string newUrl = this.Request.ServerVariables["URL"].ToString() + “?” + nvc.ToString() ;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.