473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Clear Session on page termination

I want to clear some specific Session variables when the user closes a page.
On my page I have a "return to ..." button which navigates back to the
parent page from which it was invoked - under the click event of this button
I clear my Session variables.

However, how can I capture the fact that the page has been finished with, to
clear my session variables, if the user (a) navigates away from the page
directly by entering a URL, (b) closes the window manually or (c) uses the
browser's BACK button to go back to the calling page ?

Basically I need a generic way to capture page termination, to invoke my
memory cleanup.
Nov 18 '05 #1
3 7090
Good morning,
We ran into a problem like this too but did not find a
way to do it during termination. Ie. BAck btn, URL
address chg or hitting the 'X' on the browser.

What we ended up doing was checking when the page is
loaded at the begining. Something like;
If (Session.Count > 0) Then
Session.Clear()
End If
Then you know session is empty.

Thanks
Deasun
PS. If you find out a way let us know. Thanks.
-----Original Message-----
I want to clear some specific Session variables when the user closes a page.On my page I have a "return to ..." button which navigates back to theparent page from which it was invoked - under the click event of this buttonI clear my Session variables.

However, how can I capture the fact that the page has been finished with, toclear my session variables, if the user (a) navigates away from the pagedirectly by entering a URL, (b) closes the window manually or (c) uses thebrowser's BACK button to go back to the calling page ?

Basically I need a generic way to capture page termination, to invoke mymemory cleanup.
.

Nov 18 '05 #2
One way you could do this, is by using framesets. Create a single frame
frameset, with the source set to your page. In the "onUnload" handler of
the frameset, use javascript to pop open another window, which will execute
a page to clear the session variables, and close itself when done.

In the head section of your frame page, you would have a script:

<script language="javascript">
function window_onunload()
{
window.open("/clearsession.aspx", "clearsession",
"height=100,width=100,status=no,toolbar=no,menubar =no,location=no");
}
</script>

Your frameset would have only a single page. When the frame is unloaded, it
will open the popup "clearsession.aspx" which can clear the session. We
don't put the onunload handler in the body, as we don't want to clear the
session when the page unloads for postbacks, etc - only when the user
navigates to a different URL, closes the window, or navigates back to the
parent page using the supplied link (which would target _top)

<frameset rows="100%" onUnload="window_onunload()">
<frame name="MainFrame" src="MyPage.aspx" marginwidth="0"
marginheight="0" scrolling="auto" frameborder="0">
</frameset>

The "clearsession.aspx" would simply do your memory clean up, and run
"<script>self.close</script>" on the client side to close itself when done.
This page should execute pretty quickly, and be almost transparent to the
user.

One possible problem with this, is that if the page being returned to loads
before clearsession.aspx has run, the session won't be cleared. You could
double check for this, by also checking the session in the page_load of the
page being returned to, and if the session is not clear, then clear it.

It's a bit of an awkward way to do things, but it might help achieve your
goal :-)

Hope this helps,

Mun


"JezB" <je*************@blueyonder.co.yk> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
I want to clear some specific Session variables when the user closes a page. On my page I have a "return to ..." button which navigates back to the
parent page from which it was invoked - under the click event of this button I clear my Session variables.

However, how can I capture the fact that the page has been finished with, to clear my session variables, if the user (a) navigates away from the page
directly by entering a URL, (b) closes the window manually or (c) uses the
browser's BACK button to go back to the calling page ?

Basically I need a generic way to capture page termination, to invoke my
memory cleanup.

Nov 18 '05 #3
Thanks for giving this some thought ! I'll give it a try.

"Munsifali Rashid" <mun@**RemoveToReply**vefuk.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
One way you could do this, is by using framesets. Create a single frame
frameset, with the source set to your page. In the "onUnload" handler of
the frameset, use javascript to pop open another window, which will execute a page to clear the session variables, and close itself when done.

In the head section of your frame page, you would have a script:

<script language="javascript">
function window_onunload()
{
window.open("/clearsession.aspx", "clearsession",
"height=100,width=100,status=no,toolbar=no,menubar =no,location=no");
}
</script>

Your frameset would have only a single page. When the frame is unloaded, it will open the popup "clearsession.aspx" which can clear the session. We
don't put the onunload handler in the body, as we don't want to clear the
session when the page unloads for postbacks, etc - only when the user
navigates to a different URL, closes the window, or navigates back to the
parent page using the supplied link (which would target _top)

<frameset rows="100%" onUnload="window_onunload()">
<frame name="MainFrame" src="MyPage.aspx" marginwidth="0"
marginheight="0" scrolling="auto" frameborder="0">
</frameset>

The "clearsession.aspx" would simply do your memory clean up, and run
"<script>self.close</script>" on the client side to close itself when done. This page should execute pretty quickly, and be almost transparent to the
user.

One possible problem with this, is that if the page being returned to loads before clearsession.aspx has run, the session won't be cleared. You could
double check for this, by also checking the session in the page_load of the page being returned to, and if the session is not clear, then clear it.

It's a bit of an awkward way to do things, but it might help achieve your
goal :-)

Hope this helps,

Mun


"JezB" <je*************@blueyonder.co.yk> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
I want to clear some specific Session variables when the user closes a page.
On my page I have a "return to ..." button which navigates back to the
parent page from which it was invoked - under the click event of this

button
I clear my Session variables.

However, how can I capture the fact that the page has been finished with, to
clear my session variables, if the user (a) navigates away from the page
directly by entering a URL, (b) closes the window manually or (c) uses

the browser's BACK button to go back to the calling page ?

Basically I need a generic way to capture page termination, to invoke my
memory cleanup.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same...
1
by: David | last post by:
A user logs into a web site. He is then redirected to a web page of his choosing - based on menu options - for example: "WeeklyReport.aspx" is a page the user is currently viewing If the user...
0
by: dummy_2600 | last post by:
I have an app I'm a trying to roll out to production in which Session.Clear() doesn't seem to be working for me. Basically we have multiple forms that make up a registration process. At the end...
5
by: tshad | last post by:
When I log of I do: HttpContext.Current.Session.Clear() FormsAuthentication.SignOut() The problem is that it clears the variables that I set up in my Session_Start function in my...
4
by: Eirik Eldorsen | last post by:
Is it possible to clear the generated html ouput on aspx page, and then write something else? Why? :-) I want to only the html code from a panel, and most important no form tags. Why? I'm...
1
by: ABC | last post by:
Will Session automatic clear memory when I unload web page?
2
by: ESmith | last post by:
How can I clear the current session cache of previously visited webpages? That is, say I start up my app (with browser component), point to www.cnn.com, click on several links, then I want to...
8
by: TristaSD | last post by:
Hi, I'm trying to tweak the logout script on my web projects. When I point users to a logout.php page containing the session_destroy() function, I get the "Trying to destroy uninitialized...
8
by: Michael Schwarz | last post by:
Hi, I have a problem where I have two requests (i.e. two different windows that are using the same session) that are accessing the session collection. The requests will need more time on the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.