asp.net-mvc Asp.Net MVC OnSessionStart 事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1531125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:53:12  来源:igfitidea点击:

Asp.Net MVC OnSessionStart event

asp.net-mvcsession

提问by Trimack

I have found this threadwhich describes a very interesting OnSessionStart event, but I am unable to "hook" it up (whatever it means) to my global.asax.cs. I am also unsuccessful while searching the web for it. So could someone please explain to me, if the event really exists in asp.net mvc, where do I get it (inherit or what from where) and where do I put it?

我发现这个线程描述了一个非常有趣的 OnSessionStart 事件,但我无法将它(无论它意味着什么)“挂钩”到我的 global.asax.cs。我在网上搜索时也没有成功。那么有人可以向我解释一下,如果该事件真的存在于 asp.net mvc 中,我从哪里得到它(继承或从哪里继承)以及我把它放在哪里?

回答by Palantir

It looks like this:

它看起来像这样:

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

It does work in Asp.net MVC.
Put it as a method in the class defined in Global.asax.cs, for example just after the RegisterRoutes method.

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