Session_End does not fire?

前端 未结 5 1529
眼角桃花
眼角桃花 2020-12-03 10:28

I want to sign out a user when his session times out. So used following code in Global.asax:

protected void Session_End(object sender, EventArgs e)
{
    For         


        
5条回答
  •  情歌与酒
    2020-12-03 11:09

    I don't know if it is a feature or bug. Or may be I don't understand enough session managment in ASP.NET. But this is what I found.

    Session_End does not fire in ASP.NET MVC 4 (with default settings for sessionState element in web.config) if Session_Start is not declared.

    So you need declare Session_Start to catch Session_End :)

    protected void Session_Start(Object sender, EventArgs e) { }
    
    protected void Session_End(Object sender, EventArgs e) {
      Debug.WriteLine("End. " + Session.SessionID);
    }
    

提交回复
热议问题