Session_End中 [英] Session_End

查看:55
本文介绍了Session_End中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正试图在global.asax中自动从Session_End事件中取消用户登录

。这不是一项关键的任务,更多的是家务管理任务,所以我们知道用户是否已经关闭了他们的浏览器而没有先注销

。但是,虽然代码似乎在我们的开发

服务器上运行正常,但它不能在实时服务器上运行。

我们正在使用ASP.NET v.1.1和SQL运行IIS的W2K3服务器上的Server 2000

6.


这是我们使用的c#代码: -


///< summary>


///我们可以在这里记录用户,这样数据库就可以反映正确的数字

///用户已登录。


///< / summary>


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


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


protected void Session_End(对象发送者,EventArgs e)


{


//如果用户ID不为空,自动注销...


object oId = Session [" CurrentUserId"];


try


{


if(oId!= null)


{


SqlInt 32 intUserId =

SqlInt32.Parse(oId.ToString());


SessionServer.LogOut(intUserId,

Session。 SessionID);


LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,


}


}


catch(例外情况)

{LogWriter .InsertAuditTrail(TypeServer.AuditLevel。 INFO,(null ==

oId)?SqlInt32.Null:(SqlInt32)oId,自动记录会话错误

自动。");}


}

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.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.");}

}

推荐答案

您是否在生产中使用InProc会话状态模式?


Session_End事件仅在InProc模式下引发,而不是在任何out-of-rpco

modse(StateServer,SqlServer)中引发。如果你在InProc中有它,我会怀疑

有什么东西重新启动AppDomain或者什么东西,所以

Session_End不会被提升但是那会也会导致用户每次都失去
会话,我想你会注意到这一点。


-

Teemu Keiski

ASP.NET MVP,AspInsider

芬兰,欧盟
http://blogs.aspadvice.com/joteke

" Bruno" <德******** @ hotmail.com>在消息中写道

news:44 *********************** @ news.zen.co.uk ...
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" <de********@hotmail.com> wrote in message
news:44***********************@news.zen.co.uk...
我们正在尝试从global.asax中的Session_End
事件中自动注销用户。这不是一项关键任务,而是一项家务管理任务,以便我们知道用户是否在没有首先注销的情况下关闭了浏览器。但是,虽然代码似乎在我们的开发服务器上运行正常,但它不能在实时服务器上运行。

我们正在使用ASP.NET v.1.1和SQL Server 2000 W2K3服务器运行
IIS 6.

这是我们使用的c#代码: -

///< summary>

///我们可以将用户登录到此处,以便数据库能够反映///用户登录的正确数字。

///< ; / summary>

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

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

protected void Session_End(object sender,EventArgs e)

//
//如果用户ID不是null,自动注销...

object oId = Session [" CurrentUserId"];

尝试

{

if(oId!= null)



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

SessionServer.LogOut(intUserId,
Session.SessionID);


LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,intUserId," Session
自动注销) 。;

}

catch(Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel。 INFO,(null ==
oId)?SqlInt32.Null:(SqlInt32)oId,自动记录会话的错误
。;}}

}
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.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.");}

}



我们正在使用InProc,什么可能导致AppDomain重新启动?


" Teemu Keiski" <乔**** @ aspalliance.com>在消息中写道

news:en ************** @ tk2msftngp13.phx.gbl ...
We are using InProc what could cause AppDomain to be restarted?

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
您使用的是InProc会话吗?生产中的状态模式?

Session_End事件仅在InProc模式下引发,而不是在任何out-of-rpco
modse(StateServer,SqlServer)中引发。如果你在InProc中有它,我会怀疑有什么东西重新启动AppDomain或者其他什么东西,所以
Session_End不会被提升但是这也会导致用户丢失每次会话,我想你会注意到这一点。

-
Teemu Keiski
ASP.NET MVP,AspInsider
芬兰,欧盟
http://blogs.aspadvice.com/joteke

" Bruno" <德******** @ hotmail.com>在消息中写道
新闻:44 *********************** @ news.zen.co.uk ...
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" <de********@hotmail.com> wrote in message
news:44***********************@news.zen.co.uk...
我们正在尝试从global.asax中的Session_End
事件中自动注销用户。这不是一项关键任务,而是一项家务管理任务,以便我们知道用户是否在没有首先注销的情况下关闭了浏览器。但是,虽然代码似乎在我们的开发服务器上运行正常,但它不能在实时服务器上运行。

我们正在使用ASP.NET v.1.1和SQL Server 2000 W2K3服务器运行
IIS 6.

这是我们使用的c#代码: -

///< summary>

///我们可以将用户登录到此处,以便数据库能够反映///用户登录的正确数字。

///< ; / summary>

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

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

protected void Session_End(object sender,EventArgs e)

//
//如果用户ID不是null,自动注销...

object oId = Session [" CurrentUserId"];

尝试

{

if(oId!= null)



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

SessionServer.LogOut(intUserId,
Session.SessionID);


LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,intUserId,
"会话自动退出。;

}

catch(Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel。 INFO,(null ==
oId)?SqlInt32.Null:(SqlInt32)oId,自动记录会话的错误
。;}}

}
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.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.");}

}




我们已经在实时机器和调试模式下编译了发布模式

开发机器。你认为这与它有什么关系吗?


" Bruno" <德******** @ hotmail.com>在留言中写道

news:44 ********************* @ news.zen.co.uk ...
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" <de********@hotmail.com> wrote in message
news:44*********************@news.zen.co.uk...
我们正在使用InProc,什么可能导致AppDomain重新启动?

Teemu Keiski <乔**** @ aspalliance.com>在消息中写道
新闻:en ************** @ tk2msftngp13.phx.gbl ...
We are using InProc what could cause AppDomain to be restarted?

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
您是否在生产中使用InProc会话状态模式?

Session_End事件仅在InProc模式下引发,而不是在任何out-of-rpco
modse(StateServer,SqlServer)中引发。如果你在InProc中有它,那么我会怀疑有什么东西重新启动AppDomain或者什么东西,这样就不会引发Session_End但是这也会导致用户输掉每次会话,我想你会注意到这一点。

-
Teemu Keiski
ASP.NET MVP,AspInsider
芬兰,欧盟
http://blogs.aspadvice.com/joteke

" Bruno" <德******** @ hotmail.com>在消息中写道
新闻:44 *********************** @ news.zen.co.uk ...
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" <de********@hotmail.com> wrote in message
news:44***********************@news.zen.co.uk...
我们正在尝试从global.asax中的Session_End
事件中自动注销用户。这不是一项关键任务,而是一项家务管理任务,以便我们知道用户是否在没有首先注销的情况下关闭了浏览器。但是,虽然代码似乎在我们的开发服务器上运行正常,但它不能在实时服务器上运行。

我们正在使用ASP.NET v.1.1和SQL Server 2000 W2K3服务器运行
IIS 6.

这是我们使用的c#代码: -

///< summary>

///我们可以将用户登录到此处,以便数据库能够反映///用户登录的正确数字。

///< ; / summary>

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

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

protected void Session_End(object sender,EventArgs e)

//
//如果用户ID不是null,自动注销


对象oId = Session [" CurrentUserId"];

尝试

{

if(oId!= null)



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

SessionServer.LogOut(intUserId,
Session.SessionID);


LogWriter.InsertAuditTrail(TypeServer.AuditLevel.I NFO,intUserId,
"会话自动退出。;

}

catch(Exception ex)
{LogWriter.InsertAuditTrail(TypeServer.AuditLevel。 INFO,(null ==
oId)?SqlInt32.Null:(SqlInt32)oId,自动记录会话的错误
。;}}

}
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.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.");}

}





这篇关于Session_End中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆