SessionStateModule.Start 事件


创建会话时发生的事件。The event that occurs when a session is created.

 event EventHandler ^ Start;
public event EventHandler Start;
member this.Start : EventHandler 
Public Custom Event Start As EventHandler 


下面的代码示例显示了 global.asax 文件中定义了Session_OnStartSession_OnEnd事件的内容。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 language="C#" runat="server">  
public void Session_OnStart()  
public void Session_OnEnd()  


启动新的会话时, 在请求开始时引发事件。StartThe Start event is raised at the beginning of a request when a new session is started. 如果发出的请求不包含会话标识符, 会话标识符无效, 或与会话标识符关联的会话已过期, 则启动一个新会话。A new session is started if a request is made that does not contain a session identifier, the session identifier is invalid, or the session associated with a session identifier has expired.

Session_OnStart事件用于执行会话的任何初始化工作, 例如设置会话变量的默认值。The Session_OnStart event is used to perform any initialization work for a session such as setting up default values for session variables.

可以通过将名为Session_OnStartStart公共子程序添加到 global.asax 文件来指定事件的处理程序。You can specify a handler for the Start event by adding a public subroutine named Session_OnStart to the Global.asax file.

有关 global.asax 文件的详细信息, 请参阅Global.asax 语法For more information about the Global.asax file, see Global.asax Syntax.