How to clear parameter out of url

M

moondaddy

I'm passing a parameter in the url when I open up a particular page. When
the page loads and finds this parameter, I know that I need to clear a
variable out of the session cache and reset it with a new value. On the
following postbacks I want this variable to remain constant which means I
need to clear the parameter out of the URL before any of the postbacks
occur. Otherwise if this parameter is still in the URL when the page loads
from a postback, it will clear out the variable again.

is there a way to alter the pages current URL?
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

From your description, one of your ASP.NET web page will checking a certain
querystring parameter in the requested url and do some session operations
depending on the parameter value. And currently you want to remove the
certain parameter from the request url if it exist in the first request, so
that the following postback request won't do the duplicated operations on
the session ,yes?

As far as I know, the QueryString collection of the Request object are not
modifiable by user, and I think you can consider the following means:
1.Still let the querystring param remain in the url and use the
Page.IsPostBack property to check whether its the first time loaded or post
back request so as to determine whether to do the session modification or
not.

2. User Server.Transfer or response.Redirect to reload the current page
with the non-querystring url. But this will reduce the performance.

Please have a consider on the above things. If you have any other different
ideas, please also feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
M

moondaddy

Thanks for the 2 options. #1 would be cleaner and I think I avoided some of
its performance hit by running the logic in the Page_Init method before the
line InitializeComonent executed. I used a 'redirect' and 'return' before
InitializeComonent could run. However, I ended up using #2 as it seemed to
still be a wee bit faster (although I couldn't really tell by just watching
them both run).

Thanks for the help.
 
J

John Saunders

moondaddy said:
I'm passing a parameter in the url when I open up a particular page. When
the page loads and finds this parameter, I know that I need to clear a
variable out of the session cache and reset it with a new value. On the
following postbacks I want this variable to remain constant which means I
need to clear the parameter out of the URL before any of the postbacks
occur. Otherwise if this parameter is still in the URL when the page loads
from a postback, it will clear out the variable again.

is there a way to alter the pages current URL?

If you only need that query parameter the first time you open the page, then
you should only check it on the first request. Use:

If Not Page.IsPostBack Then
If Request.QueryString("onceonly") = "doThisOnce" Then
...
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top