I'm looking for a way to get rid of the querystring of a page and redirect to itself but preserver the querystring data in some way.
Example: http://www.test.de/somepage.aspx?id=abc
should redirect to http://www.test.de/somepage.aspx
. Still, after the redirect, I want to be able to pick up the parameters that were originally passed. And I don't want to have http://www.test.de/somepage.aspx?id=abc
in the browser's history.
What I tried so far:
Response.Redirect()
: does a proper redirect without creating browser history but I cannot preserver the parameters.
Server.Transfer
: preserves the parameters but the browser's URL remains unchanged.
Create a client form on the fly and submit in onload
: works, querystring is gone, parameters are accessible through Request.Form, but creates a history entry in the browser.
The only thing I can currently think of is to store the parameters in the session, then redirect, then pick them up from there. But maybe there's still another solution?
As Pete mentioned, you can save your querystring parameters in Session and then call to Response.Redirect to redirect to the second page
Session["id"] = Request["id"];
Session["param2"] = Request["param2"];
Session["param3"] = Request["param3"];
....
Response.Redirect(sameurl);
In the second load of the page check if the querystring values are gone. If they are, instead of reading values from querystring read the values from session.
id = Session["id"];
param2 = Session["param2"];
param3 = Session["param3"];
...