2009-10-07 41 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