473,657 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session handling when user closes browser

I'm writing a .NET 2.0 app that needs to manage user sessions. We're using
SQL Server 2005 tables to hold sessions status fields in a table. The
problem is how to handle the situation where a user closes the browser
without logging out first. We're using our own authentication, not Windows.
We'd like to somehow log the user out and free up the user seat? There
doesn't seem to be a method in .net to capture the browser close event.

How is this kind of thing normally handled in .NET? Is there anything I can
do?

Thank you!!
May 21 '07 #1
4 1799
>How is this kind of thing normally handled in .NET? Is there anything I can
>do?
No really good way, due to the stateless nature of the web and your
lack of control over the browser. You can handle the onunload event on
the client and notify the server. But you have to keep in mind that
leaving a page or closing a window isn't necessarily the same as
leaving the application (the user may have multiple windows open etc).

Personally I'd rather rely on session timeout.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 21 '07 #2
Hello, actually this helps to know there's no good way to handle. We just
didn't want to overlook something that might be obvious or simple. Thanks for
your advice!
"Mattias Sjögren" wrote:
How is this kind of thing normally handled in .NET? Is there anything I can
do?

No really good way, due to the stateless nature of the web and your
lack of control over the browser. You can handle the onunload event on
the client and notify the server. But you have to keep in mind that
leaving a page or closing a window isn't necessarily the same as
leaving the application (the user may have multiple windows open etc).

Personally I'd rather rely on session timeout.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 21 '07 #3
Can you tell me if the session_end in global.asax will get triggered even if
the browser window is closed while the session is active? I don't think this
is the case but it's possible. Also, if we eventually use SQL Server for
state management, will session_end still be triggered?

Thanks!
"Mattias Sjögren" wrote:
How is this kind of thing normally handled in .NET? Is there anything I can
do?

No really good way, due to the stateless nature of the web and your
lack of control over the browser. You can handle the onunload event on
the client and notify the server. But you have to keep in mind that
leaving a page or closing a window isn't necessarily the same as
leaving the application (the user may have multiple windows open etc).

Personally I'd rather rely on session timeout.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 21 '07 #4
Upon thinking about this more, I'm wondering how I could use session-time out
as you suggested below in order to update the SQL database to log
end-of-session info like date/time of logout. If the user closes the browser,
doesn't the session just die, or is there a way to get control and do the
database update for that user?

Thanks!!

"Mattias Sjögren" wrote:
How is this kind of thing normally handled in .NET? Is there anything I can
do?

No really good way, due to the stateless nature of the web and your
lack of control over the browser. You can handle the onunload event on
the client and notify the server. But you have to keep in mind that
leaving a page or closing a window isn't necessarily the same as
leaving the application (the user may have multiple windows open etc).

Personally I'd rather rely on session timeout.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 21 '07 #5

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

Similar topics

9
3635
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk for my session variable based security scheme. Basically, the risk is that a user will login to my site, close the window when done and allow someone else to come up to the machine, go back to my site and be logged into the previous user's...
14
4060
by: Darrin J Olson | last post by:
I am trying to end a session for a site without having to completely close the browser to end it. When I access the site and log in it works fine. If I log out and in with a different account without closing the browser, I get the first session's information. Also, if a open another browser and log in with a different account I get the session from the first browser. I've tried deleting all cookies and any cached pages, but still get the...
4
4200
by: Rafael Chemtob | last post by:
Hi, I'm using session cookies on my web app and it looks like the session is not being killed when the user closes the browser. We use a Global.asa file on our app. Do we have to explicitly write to close the session or does it get killed when the user is closes their browser? Please advise. rafael
2
3336
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i don;t know how to do it?
11
5065
by: David Lozzi | last post by:
Hello All, I am having an issue with thus far one computer on my client's web site. If the user loads the shopping cart and then closes all browser windows, then opens them back up, goes back to the site, the shopping cart information is there! The shopping cart info is only loaded into a session variable! There are no cookies on the site to store this information. Am I mistaken in believing when a browser window is closed that the session...
4
2755
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been lost and show an explanatory message before restarting the session. Rather than tagging a 'session in progress' flag on the end of every request querystring I'd like to detect it using data sent in every request. One idea I had was that when...
5
9118
by: news.microsoft.com | last post by:
Hi everyone, I need some help (may be in the form of some sample code) for the subject question. I have an ASP.NET/C# application. I need to do quite a few tasks when the session ends. I don't want to depend on the session timeout factor since it may end too soon or it may hang around too long. I can't find any event that fires when the browser closes. The Session_End event handler in the Global.asax does not execute until the...
2
1805
by: Paul W | last post by:
Using default session handling (ie. inproc and with cookies). I have a 'logout' button that returns the user to the login screen and does a session.abandon. HOWEVER, if they then log back in (even with a different username) they will have the same sessionid as before! This is not what I expected. Can someone shed light on this, or how I can investigate further? Thanks, Paul.
5
548
by: Sean | last post by:
Problem with sessions I have created an application without concern for sessions. As it turns out I think that might be my undoing. What I have: I have an online quiz. I don’t need to know users or save any data. If the application crashes or user exits the program they should simply start again. Pretty basic. All interactions are stored in an array (not much going on to save to a
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.