Link to home
Start Free TrialLog in
Avatar of endrec
endrec

asked on

How to Use Response.Redirect and Pass/Keep All Existing Querystring Parameters In The Redirect

I wanted to know if there is a way to redirect the user from one page to another, but keep all the existing querystring parameters in the original page request.

Example:  User is on the URL domain.com/folder/page.aspx?key1=1&key2=yes&key3=456534234-5445435 and some action needs to redirect the user to domain2.com/folder2/page2.aspx but also pass all the existing querystring variables as the number of querystring variables in page.aspx differs occasionally (e.g. not always three querystring variables).  So the final redirect would take the user to domain2.com/folder2/page2.aspx?key1=1&key2=yes&key3=456534234-5445435 in the example.
Avatar of krunal_shah
krunal_shah

ya you can pass the query string variables in the Response.Redirect
like,

Response.Redirect("domain2.com/folder2/page2.aspx?key1=1&key2=yes&key3=456534234-5445435");
Avatar of endrec

ASKER

Ok, what if the number and value for the querystring variables is dynamic, e.g. how do I get all the querystring variables for the current page and include that in the redirect request to another page?  That's the question I'm hoping to get some aid with.
Avatar of endrec

ASKER

I'm trying to get the querystring variables for the current page then append them to the redirect to another page at some point (e.g. user clicks a particular button, some particular logic is executed).
Response.Redirect("domain2.com/folder2/page2.aspx?" + Request.QueryString.ToString());
ASKER CERTIFIED SOLUTION
Avatar of krunal_shah
krunal_shah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmmm... My solution does exactly what you asked, doesn't it? :)