Solved

Abandon Session on Browser Close or Browsing Away

Posted on 2011-02-11
5
1,192 Views
Last Modified: 2012-05-11
HI All,

When a user logs into my website is creates the Session variable UserID.

When the user logs out using the logout button, I call Session.Abandon() which in turn calls Session_End() within my Global.asax file. This function uses the UserID variable and performs a transaction against my database.

this works really well proving the user uses the damn logout button! But what I am finding is that users are either browsing away from the site or closing their browser down which isn't then performing that all important transaction against my database.

Does anyone have any magic code which can check for users browsing away or browser closing which in turn maintains the session variable whilst calling Session_End()?

Many thanks,

Rit

0
Comment
Question by:rito1
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:karthitron
karthitron earned 100 total points
ID: 34870659
While user, closing the browser, you can open your logout page and thereby you can abandon your session, if session persists and update the database. To accomplish this, use OnBeforeUnload event of your master page in body tag. For eg: here i opened google, you can open your logout functionality page.

<body OnBeforeUnload="window.open('http://www.google.co.in');">
0
 
LVL 11

Accepted Solution

by:
b_levitt earned 400 total points
ID: 34871421
This is basically what you want to do:
http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all

Is there a reason you can't rely on the session timeout?
0
 
LVL 1

Author Comment

by:rito1
ID: 34891519
Thanks both.

B_levitt, I tried to rely on Session Timeout but I want to use the session variable which didn't seem to persist long enough for the global.asax Session_End event when a browser is closed.
0
 
LVL 11

Expert Comment

by:b_levitt
ID: 34896220
I'm not sure what you mean that the session variable didn't seem to persist long enough.

Either way does the link I pasted answer your question?
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 34896260
Thanks Both, - b_levitt, thanks for the link.

Rit
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now