MVC4如何挂钩OnSessionStart事件?

时间:2013-09-23 08:31:31

标签: asp.net-mvc-4

我在VS2010中启动MVC4项目, 在Global.asax.cs中:

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(); 
    }
}

如何注册Session Start事件?

1 个答案:

答案 0 :(得分:30)

您可以将此添加到您的Global.asax.cs中,如下所示:

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
}

你也应该检查一下 http://msdn.microsoft.com/en-us/library/bb470252(v=vs.100).aspx

干杯!