web analytics

When is Session_End() called in ASP.NET MVC?

Options

codeling 1595 - 6639
@2022-06-29 15:45:57

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)
{
    FormsAuthentication.SignOut();
}

But seems session_end never fires. Any idea how can fix it? 

@2022-06-29 15:47:14

Session_end only fires in case of the Inproc session mode and not the Outproc session mode. In your web.config you need to have the sessionState element as a child of the element

<configuration>
     <system.web>
          <sessionState mode="InProc" timeout="2" />
          .....
     </system.web>
</configuration>
@2022-06-29 15:50:03

Session_End is fired internally by the server, based on an internal timer. Because of that, there is no HttpRequest associated when that happens. That is why Response.Redirect or Server.Transfer does not make sense and will not work.

@2022-06-29 15:53:33

Remember the Session_End event will not fire in the case where the user closes the browser. HTTP is a stateless protocol. So there is no way for the server to understand that the browser has been closed.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com