ASP.NET会话结束:确定事件源

ASP.NET会话结束:确定事件源,asp.net,iis,Asp.net,Iis,是否有机会检测会话超时后是否调用了会话结束方法,或者IIS本身是否在由于设置的应用程序池超时而终止会话后调用了该方法?您可以使用全局.asax的会话结束事件 会话结束事件在会话到期或应用程序池按计划回收时自动引发 private void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised

是否有机会检测会话超时后是否调用了会话结束方法,或者IIS本身是否在由于设置的应用程序池超时而终止会话后调用了该方法?

您可以使用全局.asax会话结束事件

会话结束事件在会话到期或应用程序池按计划回收时自动引发

private void Session_End(object sender, EventArgs e)
{
    // Code that runs when a session ends. 
    // Note: The Session_End event is raised only when the sessionstate mode
    // is set to InProc in the Web.config file. If session mode is set 
    // to StateServer or SQLServer, the event is not raised.
}

... 使用sender或eventargs参数无法获取“实际”源?您打算如何处理sender和eventargs?我只是好奇。基本上,如果进程因AppPool空闲关闭而终止,我必须在这个事件处理程序中运行其他逻辑。(如果可能的话)对于由于空闲而回收的应用程序池或卸载的应用程序,您可能需要使用application_End event.Thank。这是一个非常有价值的暗示。