Export (0) Print
Expand All

SessionStateModule.End Event

Occurs when a session ends.

Namespace: System.Web.SessionState
Assembly: System.Web (in system.web.dll)

public event EventHandler End
/** @event */
public void add_End (EventHandler value)

/** @event */
public void remove_End (EventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

The End event is raised at the end of a request when the Abandon method has been called or when the session has expired. A session expires when the number of minutes specified by the Timeout property passes without a request being made for the session.

The Session_OnEnd event is used to perform any cleanup work for a session such as disposing of resources used by the session.

You can specify a handler for the End event by adding a public subroutine named Session_OnEnd to the Global.asax file.

NoteNote:

The Session_OnEnd event is only supported when the session-state HttpSessionState.Mode property value is InProc, which is the default. If the session-state Mode is set to StateServer or SQLServer, then the Session_OnEnd event in the Global.asax file is ignored. If the session state Mode property value is Custom, then support for the Session_OnEnd event is determined by the custom session-state store provider.

Though the End event is public, you can only handle it by adding an event handler in the Global.asax file. This restriction is implemented because HttpApplication instances are reused for performance. When a session expires, only the Session_OnEnd event specified in the Global.asax file is executed, to prevent code from calling an End event handler associated with an HttpApplication instance that is currently in use.

For more information about the Global.asax file, see Global.asax Syntax.

The following code example shows the contents of a Global.asax file with the Session_OnStart and Session_OnEnd events defined.

<script language="VB" runat="server">
Public Sub Session_OnStart()

End Sub

Public Sub Session_OnEnd()

End Sub
</script>

<script language="C#" runat="server">
public void Session_OnStart()
{

}

public void Session_OnEnd()
{

}
</script>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft