14

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

如何注册会话开始事件?

4

1 回答 1

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

干杯!

于 2013-09-23T09:02:50.530 回答