Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global.ASAX Session_End

Status
Not open for further replies.

vituja123

Programmer
Jun 16, 2005
110
US
Hi All,

Why doesn't the Session_End sub ever fire in a clean ASAX file?

Seesion start and App Start work fine the enter opposites do not?
 
My real goal is to trap when a user closes the browser on this app so that I can clean up some database entries.

 
The session_end will fire after some minutes you specify in the web.config . Like timeout=20 which is the default.
If a user closes the browser it WONT fire. You cannot trap when a user closes his browser. That's why the timeout if for. Place the code there.
 
Exactly. How would the server know that the client had closed the browser?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the info.

But in ASP3, if you use a session variable, then close the browser, session variable is cleared.

Why is asp3 able to do that but not dotnet?

How do you create a login page logs the user out when they close the browser in dotnet?
 
session variable has to do with session_end ?
Take a look at Session.Add() and .Remove()

Example:
Session.Add("IP", Request.UserHostAddress)
Session.Count returns 1

If you close the page and open it again it returns 1 again.
The .Remove() was fired.
 
But in ASP3, if you use a session variable, then close the browser, session variable is cleared.
That simply isn't true. The session end event cannot possibly fire when the user closes the browser as the server isn't notified. The session will eventually timeout when it is due to expire (and the user may also start a new session when they submit another request to the server).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
But we've been using that technique for about 6 years now with ASP3.

A session variable holds a value when the user id/password is authenicated. If the browser is closed, the session expires.

It doesn't trigger a session end in the global.asa file but the session var is null when you start the browser up again and try linking to the asp3 app.

So ASP3 did lose the session var when the browser closed.
 
You are actually mistaken in what you think is happening here (and have been for 6 years by the sounds of it!).
If the browser is closed, the session expires.
Not true. As I said before, nothing is sent back to the server so how would it possibly know???
It doesn't trigger a session end in the global.asa file
Which proves my point above as how can the session have ended if the session on end didn't fire?
the session var is null when you start the browser up again and try linking to the asp3 app
The session variable will be null as you have initiated a new session with the server, and therefore the variable for the new session has not been set and doesn't exist (hence being null).
So ASP3 did lose the session var when the browser closed.
Nope. You just initiated a new session.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks ca8msm for the info. Now i know the how the session vars work in asp3.

 
>>Why doesn't the Session_End sub ever fire in a clean ASAX file?

like everyone said the session on end event will not fire unless the server knows about it.

but there is a workaround for this(if u can call it that).

in each page's unload you can open a popup (set the left and top property to 3000 so that it is not shown).

in the popup check if the "opener" object is valid like so:

if(opener==null)
{
//Mozilla browsers
location.href="logout.aspx"
}

if(typeof(opener.location.href)=="unknown")
{
location.href="logout.aspx"
}


but like i said, its a lot of work...


Known is handfull, Unknown is worldfull
 
and a lot of users will not allow those popups...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi,
Just my 2 cents on subject. I got a feeling that you guys are reffering to the same thing from a different angle.

1. Session_End does get called under ASP.Net
2. It will ONLY get called if your sessionState mode is set to InProc. web.config file should have this entry:
<configuration>
<system.web>
<sessionState mode="InProc"/>
</system.web>
</configuration>
3. When someone closes the browser, the Session_End will not be invoked immediately. BUT, it will be invoked AFTER the timeout (default=20minutes).
4. Therefore, there is a lag between a user is gone and before the Session_End is invoked.

Hope this info helps. cheers.

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top