Session_End

B

Bruno

We are attempting to automatically log users off from the Session_End event
in global.asax. It is not a critical task, more of a housekeeping task so
that we know if users have closed down their browsers without logging off
first. However, although the code seems to run OK on our development
servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running IIS
6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);



LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO,
intUserId, "Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
T

Teemu Keiski

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco
modse (StateServer, SqlServer). If you have it in InProc, I'd then suspect
there is something restarting the AppDomain or something, so that
Session_End wouldn't get raised but that would also cause users to lose
sessions every time and I'd think you'd have noticed that.
 
B

Bruno

We are using InProc what could cause AppDomain to be restarted?

Teemu Keiski said:
Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco
modse (StateServer, SqlServer). If you have it in InProc, I'd then suspect
there is something restarting the AppDomain or something, so that
Session_End wouldn't get raised but that would also cause users to lose
sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We are attempting to automatically log users off from the Session_End
event in global.asax. It is not a critical task, more of a housekeeping
task so that we know if users have closed down their browsers without
logging off first. However, although the code seems to run OK on our
development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running
IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
B

Bruno

We've got it compiled for release mode on the live machine and debug mode on
the development machine. Do you think that has anything to do with it?

Bruno said:
We are using InProc what could cause AppDomain to be restarted?

Teemu Keiski said:
Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco
modse (StateServer, SqlServer). If you have it in InProc, I'd then
suspect there is something restarting the AppDomain or something, so that
Session_End wouldn't get raised but that would also cause users to lose
sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We are attempting to automatically log users off from the Session_End
event in global.asax. It is not a critical task, more of a housekeeping
task so that we know if users have closed down their browsers without
logging off first. However, although the code seems to run OK on our
development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running
IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
T

Teemu Keiski

For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file
generating)
-...

But you'd notice that since your users would lose their sessions as well.
Have you noted such (if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you
haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We are using InProc what could cause AppDomain to be restarted?

Teemu Keiski said:
Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco
modse (StateServer, SqlServer). If you have it in InProc, I'd then
suspect there is something restarting the AppDomain or something, so that
Session_End wouldn't get raised but that would also cause users to lose
sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We are attempting to automatically log users off from the Session_End
event in global.asax. It is not a critical task, more of a housekeeping
task so that we know if users have closed down their browsers without
logging off first. However, although the code seems to run OK on our
development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running
IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
B

Bruno

We aren't having problems with sessions getting lost. Are there any hotfixes
or service packs which may have fixed errors with this?

Teemu Keiski said:
For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file
generating)
-...

But you'd notice that since your users would lose their sessions as well.
Have you noted such (if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you
haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We are using InProc what could cause AppDomain to be restarted?

Teemu Keiski said:
Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco
modse (StateServer, SqlServer). If you have it in InProc, I'd then
suspect there is something restarting the AppDomain or something, so
that Session_End wouldn't get raised but that would also cause users to
lose sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the Session_End
event in global.asax. It is not a critical task, more of a housekeeping
task so that we know if users have closed down their browsers without
logging off first. However, although the code seems to run OK on our
development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
T

Teemu Keiski

No,

it's normal that when AppDomain restarts, InProc sessions are lost. In this
case it means that you are not experiencing any restarts. Instead of your
log-off-code, have you tried placing something simpler into Session_End such
as writing a line to a physical file or something? To restrict that it
wouldn't be a permission issue.

You might also want to check this Session FAQ:
http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We aren't having problems with sessions getting lost. Are there any
hotfixes or service packs which may have fixed errors with this?

Teemu Keiski said:
For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file
generating)
-...

But you'd notice that since your users would lose their sessions as well.
Have you noted such (if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you
haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco
modse (StateServer, SqlServer). If you have it in InProc, I'd then
suspect there is something restarting the AppDomain or something, so
that Session_End wouldn't get raised but that would also cause users to
lose sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the Session_End
event in global.asax. It is not a critical task, more of a
housekeeping task so that we know if users have closed down their
browsers without logging off first. However, although the code seems
to run OK on our development servers, it is not working on the live
server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
B

Bruno

We've tried writing to a file aswell and there are no attempts to write to
the file according to Filemon.

Teemu Keiski said:
No,

it's normal that when AppDomain restarts, InProc sessions are lost. In
this case it means that you are not experiencing any restarts. Instead of
your log-off-code, have you tried placing something simpler into
Session_End such as writing a line to a physical file or something? To
restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ:
http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We aren't having problems with sessions getting lost. Are there any
hotfixes or service packs which may have fixed errors with this?

Teemu Keiski said:
For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file
generating)
-...

But you'd notice that since your users would lose their sessions as
well. Have you noted such (if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you
haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any
out-of-rpco modse (StateServer, SqlServer). If you have it in InProc,
I'd then suspect there is something restarting the AppDomain or
something, so that Session_End wouldn't get raised but that would also
cause users to lose sessions every time and I'd think you'd have
noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the Session_End
event in global.asax. It is not a critical task, more of a
housekeeping task so that we know if users have closed down their
browsers without logging off first. However, although the code seems
to run OK on our development servers, it is not working on the live
server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will
reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
B

Bruno

Anyone else got any ideas at all? Apparently session_start is not working
either.

Bruno said:
We've tried writing to a file aswell and there are no attempts to write to
the file according to Filemon.

Teemu Keiski said:
No,

it's normal that when AppDomain restarts, InProc sessions are lost. In
this case it means that you are not experiencing any restarts. Instead of
your log-off-code, have you tried placing something simpler into
Session_End such as writing a line to a physical file or something? To
restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ:
http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Bruno said:
We aren't having problems with sessions getting lost. Are there any
hotfixes or service packs which may have fixed errors with this?

For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file
generating)
-...

But you'd notice that since your users would lose their sessions as
well. Have you noted such (if you have, you can log for the reason
with: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ?
If you haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any
out-of-rpco modse (StateServer, SqlServer). If you have it in InProc,
I'd then suspect there is something restarting the AppDomain or
something, so that Session_End wouldn't get raised but that would
also cause users to lose sessions every time and I'd think you'd have
noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the
Session_End event in global.asax. It is not a critical task, more of
a housekeeping task so that we know if users have closed down their
browsers without logging off first. However, although the code seems
to run OK on our development servers, it is not working on the live
server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database
will reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
J

Juan T. Llibre

Bruno,

what happens if you do this :

Session("test") = "testvalue"

Can you retrieve that session value with

<%=Session("test")%>

?

If you can, Session_Start *must* have fired.

Also, check your <pages...> section in web.config and/or machine.config

Is session state enabled ?

<pages enableSessionState="true">







Bruno said:
Anyone else got any ideas at all? Apparently session_start is not working either.

Bruno said:
We've tried writing to a file aswell and there are no attempts to write to the file according to
Filemon.

Teemu Keiski said:
No,

it's normal that when AppDomain restarts, InProc sessions are lost. In this case it means that
you are not experiencing any restarts. Instead of your log-off-code, have you tried placing
something simpler into Session_End such as writing a line to a physical file or something? To
restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ: http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We aren't having problems with sessions getting lost. Are there any hotfixes or service packs
which may have fixed errors with this?

For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file generating)
-...

But you'd notice that since your users would lose their sessions as well. Have you noted such
(if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you haven't, then I
wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco modse (StateServer,
SqlServer). If you have it in InProc, I'd then suspect there is something restarting the
AppDomain or something, so that Session_End wouldn't get raised but that would also cause
users to lose sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the Session_End event in global.asax.
It is not a critical task, more of a housekeeping task so that we know if users have closed
down their browsers without logging off first. However, although the code seems to run OK
on our development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will reflect the correct
number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId = SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId, Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId, "Session logged out
automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out automatically.");}

}
 
B

Bruno

Sessions are definately working. It's just the session_end and session_start
under global.asax which aren't being fired. They work fine on the
development server but not on the live server.

Juan T. Llibre said:
Bruno,

what happens if you do this :

Session("test") = "testvalue"

Can you retrieve that session value with

<%=Session("test")%>

?

If you can, Session_Start *must* have fired.

Also, check your <pages...> section in web.config and/or machine.config

Is session state enabled ?

<pages enableSessionState="true">







Bruno said:
Anyone else got any ideas at all? Apparently session_start is not working
either.

Bruno said:
We've tried writing to a file aswell and there are no attempts to write
to the file according to Filemon.

No,

it's normal that when AppDomain restarts, InProc sessions are lost. In
this case it means that you are not experiencing any restarts. Instead
of your log-off-code, have you tried placing something simpler into
Session_End such as writing a line to a physical file or something? To
restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ:
http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We aren't having problems with sessions getting lost. Are there any
hotfixes or service packs which may have fixed errors with this?

For example

- virus scanners reading dll's in bin folder or
global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file
generating)
-...

But you'd notice that since your users would lose their sessions as
well. Have you noted such (if you have, you can log for the reason
with: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx)
? If you haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any
out-of-rpco modse (StateServer, SqlServer). If you have it in
InProc, I'd then suspect there is something restarting the
AppDomain or something, so that Session_End wouldn't get raised but
that would also cause users to lose sessions every time and I'd
think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the
Session_End event in global.asax. It is not a critical task, more
of a housekeeping task so that we know if users have closed down
their browsers without logging off first. However, although the
code seems to run OK on our development servers, it is not working
on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database
will reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId,
"Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
J

Juan T. Llibre

re:
Sessions are definately working. It's just the session_end and session_start under global.asax
which aren't being fired.

Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.

Maybe you are trying to code against objects which are not reachable from Session_Start ?




Bruno said:
Sessions are definately working. It's just the session_end and session_start under global.asax
which aren't being fired. They work fine on the development server but not on the live server.

Juan T. Llibre said:
Bruno,

what happens if you do this :

Session("test") = "testvalue"

Can you retrieve that session value with

<%=Session("test")%>

?

If you can, Session_Start *must* have fired.

Also, check your <pages...> section in web.config and/or machine.config

Is session state enabled ?

<pages enableSessionState="true">







Bruno said:
Anyone else got any ideas at all? Apparently session_start is not working either.

We've tried writing to a file aswell and there are no attempts to write to the file according
to Filemon.

No,

it's normal that when AppDomain restarts, InProc sessions are lost. In this case it means that
you are not experiencing any restarts. Instead of your log-off-code, have you tried placing
something simpler into Session_End such as writing a line to a physical file or something? To
restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ: http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We aren't having problems with sessions getting lost. Are there any hotfixes or service packs
which may have fixed errors with this?

For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file generating)
-...

But you'd notice that since your users would lose their sessions as well. Have you noted
such (if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you haven't, then I
wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco modse
(StateServer, SqlServer). If you have it in InProc, I'd then suspect there is something
restarting the AppDomain or something, so that Session_End wouldn't get raised but that
would also cause users to lose sessions every time and I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the Session_End event in
global.asax. It is not a critical task, more of a housekeeping task so that we know if
users have closed down their browsers without logging off first. However, although the
code seems to run OK on our development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will reflect the correct
number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId = SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId, Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId, "Session logged out
automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out automatically.");}

}
 
B

Bruno

Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.
A valid point, however, it is not executing the code within.
Maybe you are trying to code against objects which are not reachable from
Session_Start ?

As I mentioned we have it working on two development servers so we know it
works. Just not on the live server for some reason.

Juan T. Llibre said:
re:
Sessions are definately working. It's just the session_end and
session_start under global.asax which aren't being fired.

Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.

Maybe you are trying to code against objects which are not reachable from
Session_Start ?




Bruno said:
Sessions are definately working. It's just the session_end and
session_start under global.asax which aren't being fired. They work fine
on the development server but not on the live server.

Juan T. Llibre said:
Bruno,

what happens if you do this :

Session("test") = "testvalue"

Can you retrieve that session value with

<%=Session("test")%>

?

If you can, Session_Start *must* have fired.

Also, check your <pages...> section in web.config and/or machine.config

Is session state enabled ?

<pages enableSessionState="true">







Anyone else got any ideas at all? Apparently session_start is not
working either.

We've tried writing to a file aswell and there are no attempts to
write to the file according to Filemon.

No,

it's normal that when AppDomain restarts, InProc sessions are lost.
In this case it means that you are not experiencing any restarts.
Instead of your log-off-code, have you tried placing something
simpler into Session_End such as writing a line to a physical file or
something? To restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ:
http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We aren't having problems with sessions getting lost. Are there any
hotfixes or service packs which may have fixed errors with this?

For example

- virus scanners reading dll's in bin folder or
global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic
file generating)
-...

But you'd notice that since your users would lose their sessions as
well. Have you noted such (if you have, you can log for the reason
with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If
you haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any
out-of-rpco modse (StateServer, SqlServer). If you have it in
InProc, I'd then suspect there is something restarting the
AppDomain or something, so that Session_End wouldn't get raised
but that would also cause users to lose sessions every time and
I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the
Session_End event in global.asax. It is not a critical task,
more of a housekeeping task so that we know if users have closed
down their browsers without logging off first. However, although
the code seems to run OK on our development servers, it is not
working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database
will reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs
e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO,
intUserId, "Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
automatically.");}

}
 
J

Juan T. Llibre

I can only suggest that you post some of the offending code, then.





Bruno said:
Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.
A valid point, however, it is not executing the code within.
Maybe you are trying to code against objects which are not reachable from Session_Start ?

As I mentioned we have it working on two development servers so we know it works. Just not on the
live server for some reason.

Juan T. Llibre said:
re:
Sessions are definately working. It's just the session_end and session_start under global.asax
which aren't being fired.

Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.

Maybe you are trying to code against objects which are not reachable from Session_Start ?




Bruno said:
Sessions are definately working. It's just the session_end and session_start under global.asax
which aren't being fired. They work fine on the development server but not on the live server.

Bruno,

what happens if you do this :

Session("test") = "testvalue"

Can you retrieve that session value with

<%=Session("test")%>

?

If you can, Session_Start *must* have fired.

Also, check your <pages...> section in web.config and/or machine.config

Is session state enabled ?

<pages enableSessionState="true">







Anyone else got any ideas at all? Apparently session_start is not working either.

We've tried writing to a file aswell and there are no attempts to write to the file according
to Filemon.

No,

it's normal that when AppDomain restarts, InProc sessions are lost. In this case it means
that you are not experiencing any restarts. Instead of your log-off-code, have you tried
placing something simpler into Session_End such as writing a line to a physical file or
something? To restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ: http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We aren't having problems with sessions getting lost. Are there any hotfixes or service
packs which may have fixed errors with this?

For example

- virus scanners reading dll's in bin folder or global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic file generating)
-...

But you'd notice that since your users would lose their sessions as well. Have you noted
such (if you have, you can log for the reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ? If you haven't, then I
wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any out-of-rpco modse
(StateServer, SqlServer). If you have it in InProc, I'd then suspect there is something
restarting the AppDomain or something, so that Session_End wouldn't get raised but that
would also cause users to lose sessions every time and I'd think you'd have noticed
that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the Session_End event in
global.asax. It is not a critical task, more of a housekeeping task so that we know if
users have closed down their browsers without logging off first. However, although the
code seems to run OK on our development servers, it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the database will reflect the
correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs e)

{

// If user id is not null, log them out automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId = SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId, Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, intUserId, "Session logged out
automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null ==
oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out automatically.");}

}
 
B

Bruno

Please see original post.

Juan T. Llibre said:
I can only suggest that you post some of the offending code, then.





Bruno said:
Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.
A valid point, however, it is not executing the code within.
Maybe you are trying to code against objects which are not reachable
from Session_Start ?

As I mentioned we have it working on two development servers so we know
it works. Just not on the live server for some reason.

Juan T. Llibre said:
re:
Sessions are definately working. It's just the session_end and
session_start under global.asax which aren't being fired.

Sorry, Bruno.
If sessions are working, Session_Start *must* have fired.

Maybe you are trying to code against objects which are not reachable
from Session_Start ?




Sessions are definately working. It's just the session_end and
session_start under global.asax which aren't being fired. They work
fine on the development server but not on the live server.

Bruno,

what happens if you do this :

Session("test") = "testvalue"

Can you retrieve that session value with

<%=Session("test")%>

?

If you can, Session_Start *must* have fired.

Also, check your <pages...> section in web.config and/or
machine.config

Is session state enabled ?

<pages enableSessionState="true">







Anyone else got any ideas at all? Apparently session_start is not
working either.

We've tried writing to a file aswell and there are no attempts to
write to the file according to Filemon.

No,

it's normal that when AppDomain restarts, InProc sessions are lost.
In this case it means that you are not experiencing any restarts.
Instead of your log-off-code, have you tried placing something
simpler into Session_End such as writing a line to a physical file
or something? To restrict that it wouldn't be a permission issue.

You might also want to check this Session FAQ:
http://forums.asp.net/7504/ShowPost.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We aren't having problems with sessions getting lost. Are there
any hotfixes or service packs which may have fixed errors with
this?

For example

- virus scanners reading dll's in bin folder or
global.asax/web.config
- maximum number of dynamic page compilations teached
- directory rename under web app folder
-many file changes in the contect directories (like with dynamic
file generating)
-...

But you'd notice that since your users would lose their sessions
as well. Have you noted such (if you have, you can log for the
reason with:
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) ?
If you haven't, then I wouldn't yet investigate that possibility.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are using InProc what could cause AppDomain to be restarted?

Are you using InProc session state mode in production?

Session_End event is raised only in InProc mode, not in any
out-of-rpco modse (StateServer, SqlServer). If you have it in
InProc, I'd then suspect there is something restarting the
AppDomain or something, so that Session_End wouldn't get raised
but that would also cause users to lose sessions every time and
I'd think you'd have noticed that.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


We are attempting to automatically log users off from the
Session_End event in global.asax. It is not a critical task,
more of a housekeeping task so that we know if users have
closed down their browsers without logging off first. However,
although the code seems to run OK on our development servers,
it is not working on the live server.


We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3
server running IIS 6.

Here is the c# code we used:-

/// <summary>

/// We can log the user out here so that the
database will reflect the correct number

/// users logged in.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Session_End(object sender, EventArgs
e)

{

// If user id is not null, log them out
automatically...

object oId = Session["CurrentUserId"];



try

{

if (oId != null)

{

SqlInt32 intUserId =
SqlInt32.Parse(oId.ToString());



SessionServer.LogOut(intUserId,
Session.SessionID);




LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO,
intUserId, "Session logged out automatically.");

}

}



catch (Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel.INFO, (null
== oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session
out automatically.");}

}
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top