Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Session_Start in ASP.NET MVC?

It's quite weird, I thought that simply adding this code in the Global.asax.cs would be enough:

void Session_Start(object sender, EventArgs e) {
  // your code here, it will be executed upon session start
}

But the method isn't called... How do I let ASP.NET call a the Session_Start method when the session starts?

I can't figure how to catch the event of a session creation.

like image 596
Antoine Pelletier Avatar asked Mar 30 '17 14:03

Antoine Pelletier


1 Answers

Yes, that is enough ... when you have enabled sessions:

<system.web>
  <sessionState cookieName="auth" mode="InProc" timeout="480"/>
</system.web>
like image 50
Patrick Hofman Avatar answered Oct 15 '22 22:10

Patrick Hofman