By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

session_start/session_end

P: n/a
We are attempting to automatically log users off from the Session_End event
in global.asax and set some values on session_start. 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 (WinXP ASP.NET v. 1.1, SQL Server 2000,
IIS6), they don't seem to be firing on the live server despite sessions
working fine.

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.I NFO,
intUserId, "Session logged out automatically.");

}

}

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

}

Any ideas?

Apr 3 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hello bruno,

Session_End is not called even if browser is closed by user because HTTP
is stateless and server dont know whether you close browser.
It's is called when u call it explicit or session is expired by timeline

PS: Session_End is available onle in InProc mode

b> We are attempting to automatically log users off from the Session_End
b> event in global.asax and set some values on session_start. It is not
b> a critical task, more of a housekeeping task so that we know if users
b> have closed down their browsers without logging off first. However,
b> although the code seems to run OK on our development servers (WinXP
b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be firing
b> on the live server despite sessions working fine.
b>
b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
b> running IIS 6.
b>
b> Here is the c# code we used:-
b>
b> /// <summary>
b>
b> /// We can log the user out here so that the database
b> will reflect the correct number
b>
b> /// users logged in.
b>
b> /// </summary>
b>
b> /// <param name="sender"></param>
b>
b> /// <param name="e"></param>
b>
b> protected void Session_End(object sender, EventArgs e)
b>
b> {
b>
b> // If user id is not null, log them out
b> automatically...
b>
b> object oId = Session["CurrentUserId"];
b>
b> try
b>
b> {
b>
b> if (oId != null)
b>
b> {
b>
b> SqlInt32 intUserId =
b> SqlInt32.Parse(oId.ToString());
b>
b> SessionServer.LogOut(intUserId,
b> Session.SessionID);
b>
b>
b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO, intUserId,
b> "Session logged out automatically.");
b>
b> }
b>
b> }
b>
b> catch (Exception ex)
b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
b> automatically.");}
b>
b> }
b>
b> Any ideas?
b>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Apr 3 '06 #2

P: n/a
We are using InProc and we are aware of how it is supposed to function.

To clarify. It _is_ working on our development servers but _not_ on the live
server.
"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello bruno,

Session_End is not called even if browser is closed by user because HTTP
is stateless and server dont know whether you close browser.
It's is called when u call it explicit or session is expired by timeline

PS: Session_End is available onle in InProc mode

b> We are attempting to automatically log users off from the Session_End
b> event in global.asax and set some values on session_start. It is not
b> a critical task, more of a housekeeping task so that we know if users
b> have closed down their browsers without logging off first. However,
b> although the code seems to run OK on our development servers (WinXP
b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be firing
b> on the live server despite sessions working fine.
b> b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3 server
b> running IIS 6.
b> b> Here is the c# code we used:-
b> b> /// <summary>
b> b> /// We can log the user out here so that the database
b> will reflect the correct number
b> b> /// users logged in.
b> b> /// </summary>
b> b> /// <param name="sender"></param>
b> b> /// <param name="e"></param>
b> b> protected void Session_End(object sender, EventArgs e)
b> b> {
b> b> // If user id is not null, log them out
b> automatically...
b> b> object oId = Session["CurrentUserId"];
b> b> try
b> b> {
b> b> if (oId != null)
b> b> {
b> b> SqlInt32 intUserId =
b> SqlInt32.Parse(oId.ToString());
b> b> SessionServer.LogOut(intUserId,
b> Session.SessionID);
b> b> b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO, intUserId,
b> "Session logged out automatically.");
b> b> }
b> b> }
b> b> catch (Exception ex)
b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
b> automatically.");}
b> b> }
b> b> Any ideas?
b> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Apr 3 '06 #3

P: n/a
Hello bruno,

Sorry, missed it
Have u tried this one http://support.microsoft.com/?kbid=827164 ?
b> We are using InProc and we are aware of how it is supposed to
b> function.
b>
b> To clarify. It _is_ working on our development servers but _not_ on
b> the live server.
b>
b> "Michael Nemtsev" <ne*****@msn.com> wrote in message
b> news:9c**************************@msnews.microsoft .com...
b>
Hello bruno,

Session_End is not called even if browser is closed by user because
HTTP
is stateless and server dont know whether you close browser.
It's is called when u call it explicit or session is expired by
timeline
PS: Session_End is available onle in InProc mode

b> We are attempting to automatically log users off from the
Session_End
b> event in global.asax and set some values on session_start. It is
not
b> a critical task, more of a housekeeping task so that we know if
users
b> have closed down their browsers without logging off first.
However,
b> although the code seems to run OK on our development servers
(WinXP
b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be
firing
b> on the live server despite sessions working fine.
b> b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3
server
b> running IIS 6.
b> b> Here is the c# code we used:-
b> b> /// <summary>
b> b> /// We can log the user out here so that the database
b> will reflect the correct number
b> b> /// users logged in.
b> b> /// </summary>
b> b> /// <param name="sender"></param>
b> b> /// <param name="e"></param>
b> b> protected void Session_End(object sender, EventArgs e)
b> b> {
b> b> // If user id is not null, log them out
b> automatically...
b> b> object oId = Session["CurrentUserId"];
b> b> try
b> b> {
b> b> if (oId != null)
b> b> {
b> b> SqlInt32 intUserId =
b> SqlInt32.Parse(oId.ToString());
b> b> SessionServer.LogOut(intUserId,
b> Session.SessionID);
b> b> b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,
intUserId,
b> "Session logged out automatically.");
b> b> }
b> b> }
b> b> catch (Exception ex)
b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
b> automatically.");}
b> b> }
b> b> Any ideas?
b> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Apr 3 '06 #4

P: n/a
Hello bruno,

And check if correct version of ASP.net 1.1 is set in the Virtual Folder
properties of your site in IIS

b> We are using InProc and we are aware of how it is supposed to
b> function.
b>
b> To clarify. It _is_ working on our development servers but _not_ on
b> the live server.
b>
b> "Michael Nemtsev" <ne*****@msn.com> wrote in message
b> news:9c**************************@msnews.microsoft .com...
b>
Hello bruno,

Session_End is not called even if browser is closed by user because
HTTP
is stateless and server dont know whether you close browser.
It's is called when u call it explicit or session is expired by
timeline
PS: Session_End is available onle in InProc mode

b> We are attempting to automatically log users off from the
Session_End
b> event in global.asax and set some values on session_start. It is
not
b> a critical task, more of a housekeeping task so that we know if
users
b> have closed down their browsers without logging off first.
However,
b> although the code seems to run OK on our development servers
(WinXP
b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be
firing
b> on the live server despite sessions working fine.
b> b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3
server
b> running IIS 6.
b> b> Here is the c# code we used:-
b> b> /// <summary>
b> b> /// We can log the user out here so that the database
b> will reflect the correct number
b> b> /// users logged in.
b> b> /// </summary>
b> b> /// <param name="sender"></param>
b> b> /// <param name="e"></param>
b> b> protected void Session_End(object sender, EventArgs e)
b> b> {
b> b> // If user id is not null, log them out
b> automatically...
b> b> object oId = Session["CurrentUserId"];
b> b> try
b> b> {
b> b> if (oId != null)
b> b> {
b> b> SqlInt32 intUserId =
b> SqlInt32.Parse(oId.ToString());
b> b> SessionServer.LogOut(intUserId,
b> Session.SessionID);
b> b> b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,
intUserId,
b> "Session logged out automatically.");
b> b> }
b> b> }
b> b> catch (Exception ex)
b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
b> automatically.");}
b> b> }
b> b> Any ideas?
b> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Apr 3 '06 #5

P: n/a
It's definately using the right version.

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello bruno,

And check if correct version of ASP.net 1.1 is set in the Virtual Folder
properties of your site in IIS

b> We are using InProc and we are aware of how it is supposed to
b> function.
b> b> To clarify. It _is_ working on our development servers but _not_ on
b> the live server.
b> b> "Michael Nemtsev" <ne*****@msn.com> wrote in message
b> news:9c**************************@msnews.microsoft .com...
b>
Hello bruno,

Session_End is not called even if browser is closed by user because
HTTP
is stateless and server dont know whether you close browser.
It's is called when u call it explicit or session is expired by
timeline
PS: Session_End is available onle in InProc mode

b> We are attempting to automatically log users off from the
Session_End
b> event in global.asax and set some values on session_start. It is
not
b> a critical task, more of a housekeeping task so that we know if
users
b> have closed down their browsers without logging off first.
However,
b> although the code seems to run OK on our development servers
(WinXP
b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be
firing
b> on the live server despite sessions working fine.
b> b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3
server
b> running IIS 6.
b> b> Here is the c# code we used:-
b> b> /// <summary>
b> b> /// We can log the user out here so that the database
b> will reflect the correct number
b> b> /// users logged in.
b> b> /// </summary>
b> b> /// <param name="sender"></param>
b> b> /// <param name="e"></param>
b> b> protected void Session_End(object sender, EventArgs e)
b> b> {
b> b> // If user id is not null, log them out
b> automatically...
b> b> object oId = Session["CurrentUserId"];
b> b> try
b> b> {
b> b> if (oId != null)
b> b> {
b> b> SqlInt32 intUserId =
b> SqlInt32.Parse(oId.ToString());
b> b> SessionServer.LogOut(intUserId,
b> Session.SessionID);
b> b> b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,
intUserId,
b> "Session logged out automatically.");
b> b> }
b> b> }
b> b> catch (Exception ex)
b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
b> automatically.");}
b> b> }
b> b> Any ideas?
b> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Apr 4 '06 #6

P: n/a
Session is firing on your dev server but not in production, is that right?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Bruno" <de********@hotmail.com> wrote in message
news:44*********************@news.zen.co.uk...
It's definately using the right version.

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello bruno,

And check if correct version of ASP.net 1.1 is set in the Virtual Folder
properties of your site in IIS

b> We are using InProc and we are aware of how it is supposed to
b> function.
b> b> To clarify. It _is_ working on our development servers but _not_ on
b> the live server.
b> b> "Michael Nemtsev" <ne*****@msn.com> wrote in message
b> news:9c**************************@msnews.microsoft .com...
b>
Hello bruno,

Session_End is not called even if browser is closed by user because
HTTP
is stateless and server dont know whether you close browser.
It's is called when u call it explicit or session is expired by
timeline
PS: Session_End is available onle in InProc mode

b> We are attempting to automatically log users off from the
Session_End
b> event in global.asax and set some values on session_start. It is
not
b> a critical task, more of a housekeeping task so that we know if
users
b> have closed down their browsers without logging off first.
However,
b> although the code seems to run OK on our development servers
(WinXP
b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be
firing
b> on the live server despite sessions working fine.
b> b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3
server
b> running IIS 6.
b> b> Here is the c# code we used:-
b> b> /// <summary>
b> b> /// We can log the user out here so that the database
b> will reflect the correct number
b> b> /// users logged in.
b> b> /// </summary>
b> b> /// <param name="sender"></param>
b> b> /// <param name="e"></param>
b> b> protected void Session_End(object sender, EventArgs e)
b> b> {
b> b> // If user id is not null, log them out
b> automatically...
b> b> object oId = Session["CurrentUserId"];
b> b> try
b> b> {
b> b> if (oId != null)
b> b> {
b> b> SqlInt32 intUserId =
b> SqlInt32.Parse(oId.ToString());
b> b> SessionServer.LogOut(intUserId,
b> Session.SessionID);
b> b> b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,
intUserId,
b> "Session logged out automatically.");
b> b> }
b> b> }
b> b> catch (Exception ex)
b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
b> automatically.");}
b> b> }
b> b> Any ideas?
b> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche


Apr 5 '06 #7

P: n/a
Yes that is right.

"Alvin Bruney" <va******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Session is firing on your dev server but not in production, is that right?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Bruno" <de********@hotmail.com> wrote in message
news:44*********************@news.zen.co.uk...
It's definately using the right version.

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello bruno,

And check if correct version of ASP.net 1.1 is set in the Virtual Folder
properties of your site in IIS

b> We are using InProc and we are aware of how it is supposed to
b> function.
b> b> To clarify. It _is_ working on our development servers but _not_
on
b> the live server.
b> b> "Michael Nemtsev" <ne*****@msn.com> wrote in message
b> news:9c**************************@msnews.microsoft .com...
b>
> Hello bruno,
>
> Session_End is not called even if browser is closed by user because
> HTTP
> is stateless and server dont know whether you close browser.
> It's is called when u call it explicit or session is expired by
> timeline
> PS: Session_End is available onle in InProc mode
>
> b> We are attempting to automatically log users off from the
> Session_End
> b> event in global.asax and set some values on session_start. It is
> not
> b> a critical task, more of a housekeeping task so that we know if
> users
> b> have closed down their browsers without logging off first.
> However,
> b> although the code seems to run OK on our development servers
> (WinXP
> b> ASP.NET v. 1.1, SQL Server 2000, IIS6), they don't seem to be
> firing
> b> on the live server despite sessions working fine.
> b> b> We are using ASP.NET v. 1.1 and SQL Server 2000 on a W2K3
> server
> b> running IIS 6.
> b> b> Here is the c# code we used:-
> b> b> /// <summary>
> b> b> /// We can log the user out here so that the database
> b> will reflect the correct number
> b> b> /// users logged in.
> b> b> /// </summary>
> b> b> /// <param name="sender"></param>
> b> b> /// <param name="e"></param>
> b> b> protected void Session_End(object sender, EventArgs e)
> b> b> {
> b> b> // If user id is not null, log them out
> b> automatically...
> b> b> object oId = Session["CurrentUserId"];
> b> b> try
> b> b> {
> b> b> if (oId != null)
> b> b> {
> b> b> SqlInt32 intUserId =
> b> SqlInt32.Parse(oId.ToString());
> b> b> SessionServer.LogOut(intUserId,
> b> Session.SessionID);
> b> b> b> LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,
> intUserId,
> b> "Session logged out automatically.");
> b> b> }
> b> b> }
> b> b> catch (Exception ex)
> b> {LogWriter.InsertAuditTrail(TypeServer.AuditLevel. INFO, (null ==
> b> oId)?SqlInt32.Null:(SqlInt32)oId, "Error logging session out
> b> automatically.");}
> b> b> }
> b> b> Any ideas?
> b> ---
> WBR,
> Michael Nemtsev :: blog: http://spaces.msn.com/laflour
> "At times one remains faithful to a cause only because its opponents
> do not cease to be insipid." (c) Friedrich Nietzsche
>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche



Apr 5 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.