Solved

Abandon Session on Browser Close or Browsing Away

Posted on 2011-02-11
5
1,196 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

939 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

11 Experts available now in Live!

Get 1:1 Help Now