问题描述
我正在使用 MVC6 开发应用程序.我注意到默认情况下 Global.asax
文件消失了,有一个调用配置的 startup.cs
文件.我的问题是如何获取 Application_Start
事件方法?
I'm developing an application using MVC6.I noticed that the Global.asax
file disappeared by default there is startup.cs
file that calls the config. My question is how do I grab the Application_Start
event method ?
我还需要 Global.asax
吗?为什么默认去掉了?
Do I still need the Global.asax
?Why has it been removed by default ?
推荐答案
Global.asax 仅在有理由挂钩时才会出现.默认的 MVC6 项目没有钩子,因此它不提供钩子.只需添加新项目 global.asax
Global.asax is only present when there is a reason to hook into it. The default MVC6 project has no hooks into it, therefore it doesn't provide one. Just add new item, global.asax
我还应该建议,除非您绝对需要,否则我会避免创建 global.asax.当可能有更好的地方可以做您需要做的事情时,人们往往会首先使用 Application_Start 或 Session_Start.考虑创建一个 OWIN 模块,或考虑添加您自己的启动模块.
I should also suggest, that I would avoid creating a global.asax unless you need absolutely need it. People tend to reach for Application_Start or Session_Start first when there are probably better places to do what you need to do. Consider creating an OWIN module, or consider adding your own Startup module.
这篇关于带有 vNext 的 MVC 6:我们还需要 Global.asax 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!