Session_End never fires

K

Kenn Ghannon

I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kevin Spencer

How do you know for sure that it NEVER fires? The Session_End Event happens
usually some time after the user has closed their browser or navigated
elsewhere. As the server has no idea what is happening on the client, the
Session ends 20 (by default, and according to your web.config file) minutes
after the last Request from that user. So, again, are you sure it is NEVER
firing?

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.
 
K

Kenn Ghannon

I print the value of the curUsers counter (along with another one that is
supposed to keep track of the number of users that have ever visited the
site) on the home page. The values of these two counters are ALWAYS equal
and get reset at the same time (I've had both counters up to over 2000
before the application ended and each counter was reset to 0...because I
have a Application_End() routine that is supposed to save the counter to a
file -- and an accompanying Application_Start() routine to read it in so
that when the application starts again, I can start counting where I left
off -- but never seems to fire either. The counter file is always set to
0).


Kevin Spencer said:
How do you know for sure that it NEVER fires? The Session_End Event happens
usually some time after the user has closed their browser or navigated
elsewhere. As the server has no idea what is happening on the client, the
Session ends 20 (by default, and according to your web.config file) minutes
after the last Request from that user. So, again, are you sure it is NEVER
firing?

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

Kenn Ghannon said:
I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
D

David Waz...

look for code logic problems, cause it will fire - i promise!

also, you can force the event with SESSION.ABANDON method... and place a
break-point to debug the routine...


Kenn Ghannon said:
I print the value of the curUsers counter (along with another one that is
supposed to keep track of the number of users that have ever visited the
site) on the home page. The values of these two counters are ALWAYS equal
and get reset at the same time (I've had both counters up to over 2000
before the application ended and each counter was reset to 0...because I
have a Application_End() routine that is supposed to save the counter to a
file -- and an accompanying Application_Start() routine to read it in so
that when the application starts again, I can start counting where I left
off -- but never seems to fire either. The counter file is always set to
0).


Kevin Spencer said:
How do you know for sure that it NEVER fires? The Session_End Event happens
usually some time after the user has closed their browser or navigated
elsewhere. As the server has no idea what is happening on the client, the
Session ends 20 (by default, and according to your web.config file) minutes
after the last Request from that user. So, again, are you sure it is NEVER
firing?

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

Kenn Ghannon said:
I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kenn Ghannon

No real error handling...but I've even gone so far as to put a
Session.Abandon() call in my code-behind file...and it STILL does not end.
Here're the particulars:

From my home.aspx.cs file:
private void Page_Load(object sender, System.EventArgs e)

{

orgLog myLog = (orgLog)Application["orgLog"];

myLog.WriteLine( "Testing" );

Session.Abandon();

}

From my global.asax.cs file:
protected void Session_Start(Object sender, EventArgs e)

{

orgLog LogFile;

Application.Lock();

LogFile = (orgLog)Application["orgLog"];

Application.UnLock();

Session["IPADDR"] = "19.19.19.19"; // just used to store something in the
session

LogFile.WriteLine( ":: Session Begins for " +
Request.ServerVariables["REMOTE_ADDR"].ToString() );

}

protected void Session_End(Object sender, EventArgs e)

{

orgLog LogFile;

Application.Lock();

LogFile = (orgLog)Application["orgLog"];

Application.UnLock();

LogFile.WriteLine( ":: Session Ends for " +
Request.ServerVariables["REMOTE_ADDR"].ToString() );

}

// orgLog is a home made information logging tool (it creates a log file).
I'd think that maybe the problem is here, but I can log to it over and over
without difficulty..

From the Log File:

[7/9/2003 4:10:37 PM] == Application Starts ==
[7/9/2003 4:10:38 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:10:38 PM] Testing
[7/9/2003 4:25:25 PM] == Application Starts ==
[7/9/2003 4:25:25 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:25:25 PM] Testing
[7/9/2003 4:30:27 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:30:27 PM] Testing
[7/9/2003 4:30:28 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:30:28 PM] Testing

Notice that I'm getting a new Session for each iteration (I'm not sure why)
but I'm never getting a Session_End...

If anyone notices anything out of place, please let me know. I've got my
session timeout set to 1, so I should be getting the session_end after a
minute...but I just seem to be getting a new session without the old session
ever ending...

Kevin Spencer said:
What sort of error-handling are you implementing for this? It sounds like an
error may be aborting the process somewhere.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

Kenn Ghannon said:
I print the value of the curUsers counter (along with another one that is
supposed to keep track of the number of users that have ever visited the
site) on the home page. The values of these two counters are ALWAYS equal
and get reset at the same time (I've had both counters up to over 2000
before the application ended and each counter was reset to 0...because I
have a Application_End() routine that is supposed to save the counter to a
file -- and an accompanying Application_Start() routine to read it in so
that when the application starts again, I can start counting where I left
off -- but never seems to fire either. The counter file is always set to
0).


Kevin Spencer said:
How do you know for sure that it NEVER fires? The Session_End Event happens
usually some time after the user has closed their browser or navigated
elsewhere. As the server has no idea what is happening on the client, the
Session ends 20 (by default, and according to your web.config file) minutes
after the last Request from that user. So, again, are you sure it is NEVER
firing?

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users
that
are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kenn Ghannon

Actually, I DO know why...the added Session.Abandon()...but it still never
goes to Session_End...


Kenn Ghannon said:
No real error handling...but I've even gone so far as to put a
Session.Abandon() call in my code-behind file...and it STILL does not end.
Here're the particulars:

From my home.aspx.cs file:
private void Page_Load(object sender, System.EventArgs e)

{

orgLog myLog = (orgLog)Application["orgLog"];

myLog.WriteLine( "Testing" );

Session.Abandon();

}

From my global.asax.cs file:
protected void Session_Start(Object sender, EventArgs e)

{

orgLog LogFile;

Application.Lock();

LogFile = (orgLog)Application["orgLog"];

Application.UnLock();

Session["IPADDR"] = "19.19.19.19"; // just used to store something in the
session

LogFile.WriteLine( ":: Session Begins for " +
Request.ServerVariables["REMOTE_ADDR"].ToString() );

}

protected void Session_End(Object sender, EventArgs e)

{

orgLog LogFile;

Application.Lock();

LogFile = (orgLog)Application["orgLog"];

Application.UnLock();

LogFile.WriteLine( ":: Session Ends for " +
Request.ServerVariables["REMOTE_ADDR"].ToString() );

}

// orgLog is a home made information logging tool (it creates a log file).
I'd think that maybe the problem is here, but I can log to it over and over
without difficulty..

From the Log File:

[7/9/2003 4:10:37 PM] == Application Starts ==
[7/9/2003 4:10:38 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:10:38 PM] Testing
[7/9/2003 4:25:25 PM] == Application Starts ==
[7/9/2003 4:25:25 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:25:25 PM] Testing
[7/9/2003 4:30:27 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:30:27 PM] Testing
[7/9/2003 4:30:28 PM] :: Session Begins for 127.0.0.1
[7/9/2003 4:30:28 PM] Testing

Notice that I'm getting a new Session for each iteration (I'm not sure why)
but I'm never getting a Session_End...

If anyone notices anything out of place, please let me know. I've got my
session timeout set to 1, so I should be getting the session_end after a
minute...but I just seem to be getting a new session without the old session
ever ending...

Kevin Spencer said:
What sort of error-handling are you implementing for this? It sounds
like
an
error may be aborting the process somewhere.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.
to
a
file -- and an accompanying Application_Start() routine to read it in so
that when the application starts again, I can start counting where I left
off -- but never seems to fire either. The counter file is always set to
0).


How do you know for sure that it NEVER fires? The Session_End Event
happens
usually some time after the user has closed their browser or navigated
elsewhere. As the server has no idea what is happening on the
client,
the
Session ends 20 (by default, and according to your web.config file)
minutes
after the last Request from that user. So, again, are you sure it is NEVER
firing?

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that
are
logged into the system by keeping track of the number of open
sessions --
except that the Session_End NEVER fires. I've checked my web.config
file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kevin Spencer

Of course the Request object is invalid on Session_End! The Session ends
AFTER the last Request has been processed!

--
HTH,

Kevin Spencer
..Net Developer
Microsoft MVP
http://www.takempis.com
Big things are made up
of lots of little things

Kenn Ghannon said:
Please excuse me for being a freaking newbie. :) I didn't know that you
could debug the global.asax.cs file...

Turns out that the Request object is no longer valid during Session_End (It
says there's an HTML Exception when doing a 'Watch' of the Request object --
but I'm not doing anything weird and I've walked it until the session timed
out -- and the Request object was valid when the page rendered and wasn't
when it came back to Session_End...

Kenn Ghannon said:
I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kevin Spencer

BTW, using some try/catch blocks in your code would have helped you debug a
good bit. For example, you could have the app write an Event Log entry with
a Stack Trace and the error details when an error occurs. That way you would
know exactly where any error occurs.

--
HTH,

Kevin Spencer
..Net Developer
Microsoft MVP
http://www.takempis.com
Big things are made up
of lots of little things

Kenn Ghannon said:
Please excuse me for being a freaking newbie. :) I didn't know that you
could debug the global.asax.cs file...

Turns out that the Request object is no longer valid during Session_End (It
says there's an HTML Exception when doing a 'Watch' of the Request object --
but I'm not doing anything weird and I've walked it until the session timed
out -- and the Request object was valid when the page rendered and wasn't
when it came back to Session_End...

Kenn Ghannon said:
I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kenn Ghannon

You're right...but my development machine is not going to be where the app
finally resides and I don't have access to the Event log of that server --
so I've been trying to make do without using traces...


Kevin Spencer said:
BTW, using some try/catch blocks in your code would have helped you debug a
good bit. For example, you could have the app write an Event Log entry with
a Stack Trace and the error details when an error occurs. That way you would
know exactly where any error occurs.

--
HTH,

Kevin Spencer
.Net Developer
Microsoft MVP
http://www.takempis.com
Big things are made up
of lots of little things

Kenn Ghannon said:
Please excuse me for being a freaking newbie. :) I didn't know that you
could debug the global.asax.cs file...

Turns out that the Request object is no longer valid during Session_End (It
says there's an HTML Exception when doing a 'Watch' of the Request object --
but I'm not doing anything weird and I've walked it until the session timed
out -- and the Request object was valid when the page rendered and wasn't
when it came back to Session_End...

Kenn Ghannon said:
I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users that are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 
K

Kevin Spencer

Well, what you can do is write a global Error Handler method that all of
your outermost try/catch blocks use. Then you can change the implementation
of that Error Handler whenever you feel that it is appropriate for the
platform you're running the app on. In any case, it's a good idea to have
some kind of "graceful" error-handling in whatever situation you're in.

--
HTH,

Kevin Spencer
..Net Developer
Microsoft MVP
http://www.takempis.com
Big things are made up
of lots of little things

Kenn Ghannon said:
You're right...but my development machine is not going to be where the app
finally resides and I don't have access to the Event log of that server --
so I've been trying to make do without using traces...


Kevin Spencer said:
BTW, using some try/catch blocks in your code would have helped you
debug
a
good bit. For example, you could have the app write an Event Log entry with
a Stack Trace and the error details when an error occurs. That way you would
know exactly where any error occurs.

--
HTH,

Kevin Spencer
.Net Developer
Microsoft MVP
http://www.takempis.com
Big things are made up
of lots of little things

Kenn Ghannon said:
Please excuse me for being a freaking newbie. :) I didn't know that you
could debug the global.asax.cs file...

Turns out that the Request object is no longer valid during
Session_End
(It
says there's an HTML Exception when doing a 'Watch' of the Request object --
but I'm not doing anything weird and I've walked it until the session timed
out -- and the Request object was valid when the page rendered and wasn't
when it came back to Session_End...

I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:

protected void Session_End(Object sender, EventArgs e)

{

ulong curUsers;

Application.Lock();

curUsers = (ulong)Application["curUsers"];

curUsers--;

Application["iCurUsers"] = curUsers;

Application.UnLock();

}

Basically, this is supposed to keep track of the number of users
that
are
logged into the system by keeping track of the number of open sessions --
except that the Session_End NEVER fires. I've checked my web.config file
and it does show the mode as InProc:

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

Is there something else I missed??
 

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

Members online

Forum statistics

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

Latest Threads

Top