2009-10-07 35 views
38

我发现了this thread它描述了一个非常有趣的OnSessionStart事件,但我无法将它挂钩(不管它是什么意思)给我的global.asax.cs。在搜索网页时我也没有成功。那么有人可以向我解释一下,如果事件真的存在于asp.net mvc中,我可以从哪里获得它(继承或从哪里获得)以及我在哪里放置它?Asp.Net MVC OnSessionStart事件

回答

74

它看起来像这样:

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

它在Asp.net MVC的工作。
将它作为Global.asax.cs中定义的类中的方法,例如在RegisterRoutes方法之后。

+3

链接已损坏。这是另一个提供类似信息的地方:http://sandblogaspnet.blogspot.com/2008/03/methods-in-globalasax.html – flipchart 2013-09-12 04:48:34