Sunday, 11 December 2016

C# - Update Querystring Values in a Url

We will look into a solution to update querystring values in a Url.

using System.Web;

// url has the complete url with querystring 
// ex: http://bing.com?abc=1xyz=20
var uriBuilder = new UriBuilder(url);

var query = HttpUtility.ParseQueryString(uriBuilder.Query);

// Existing Querystring parameter xyz value will be updated from 20 to 10
query["xyz"] = "10";

// As QS Parameter hello doesn't existed, it will be added.
query["hello"] = "world";

// Set updated querystring to the Url.
uriBuilder.Query = query.ToString();

// New Url: http://bing.com?abc=1xyz=10&hello=world
Response.Redirect(uriBuilder.ToString()); 

Remember to import namespace "System.Web"

1 comment:

  1. Call McAfee Support phone number 1-855-966-3855, We are third party service provider for a McAfee Customer Service and McAfee Customer Support and not in any way associated with McAfee or any of its partner companies. We offer McAfee Technical Support for McAfee products and sell subscription based additional warranty on computer and other peripheral devices. Our number is toll free within USA and Canada but our services are paid, if you opt for them.

    We not only fix McAfee related issues, but also other antivirus issues. If you need help with your antivirus. Please call our McAfee Phone Number support line at Toll Free 1-855-966-3855. Thank you for choosing our support

    ReplyDelete