I start MVC4 project in VS2010, In Global.asax.cs like :
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
}
how to register Session Start event ?
Sessions values can be stored for the duration of the visitor's session on your site. Most cases, they are stored in server memory. You can configure session to store either in State server or in SQL Server. In ASP.NET MVC, you can create and access session variables using HttpContext.
ASP.NET MVC provides three ways (TempData, ViewData and ViewBag) to manage session, apart from that we can use session variable, hidden fields and HTML controls for the same. But like session variable these elements cannot preserve values for all requests; value persistence varies depending the flow of request.
You can just add this to your Global.asax.cs like this:
protected void Session_Start(object sender, EventArgs e)
{
// event is raised each time a new session is created
}
protected void Session_End(object sender, EventArgs e)
{
// event is raised when a session is abandoned or expires
}
You should also probably check http://msdn.microsoft.com/en-us/library/bb470252(v=vs.100).aspx
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With