session_end when triggerd?

G

gce

Hi,

Every session I make a temp directory using Session("SessieGuid") =
System.Guid.NewGuid().ToString
Whenever the user presses a button to end everything or when the
session.timeout fires up, I need to remove the directory.

My question :

1. What command is needed behind the END-button to close the session
2. And when will session_end will fire up?

Best regards,
gert
 
A

Andy Fish

To end the session, I think the best practice is to call

Session.Clear();
Session.Abandon();

in that order.

if you do this, the Session_End event will be called immediately (in the
same thread I think). Otherwise it will be called when the user's session is
timed out, which depends on the <sessionState timeout="..." > in
web.config.

AFAIK, this only works with <sessionState mode="InProc"> which is the
default.

Andy
 
P

Patrice

Session_end occurs twenty minutes (by default) after having no news from the
user.You can use Session.Abandon to force this.

Traditionaly this is not considered always reliable (not sure it will fire
if ASP.NET is recycled) (note also that the SQL Server session provider
doesn't fire AFAIK this event).

My personal preference is to have my housekeeping tasks kept independant
from the application control flow. For example here you could kill those
dirs one day later or even I would try to see if I really need those
dirs...(you could name files using those GUIDs, you could make them not
available on the Internet if this is the case for this scheme etc...)

Patrice
 
T

Teemu Keiski

Explicit call to Session.Abandon will end the session and lets End event to
be raised (which happens when SessionStateModule gets the response for
postprocessing), but this happens only in InProc session mode.
 
G

gce

I am a relative newbie and an old fashion vb6 programmer so forgive me
stupid questions.

I run it on a testserver in vmware locally. In web.config the INPROC is set.
The session.timer is set to 1 in the session_start part op global.

I made a button with :

session.clear
session.abandon

but the statements that are in session_end won't fire up.

Other options are not there for me. The site is hosted externally and I can
not do scheduled things there i think.
 
A

Andy Fish

It looks like you're doing the right thing.

If you're just going straight in and clicking the end button it may be that
you do not actually have a session. I'm not 100% sure about this but it's
possible you need to do a round-trip to the browser to properly establish a
session i.e. make sure you put something in the session when the page is
originally displayed.

if it's not that, try waiting until the session is timed out and see if the
session_end is fired then. This will tell you whether sessions_end is
working

as Patrice said, you should not rely 100% on this mechanism anyway. What I
do in this situation is put some code into application_start to clear down
all the directories for all users. Use this in conjunction with the
session_end.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top