Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

asp.net mvc - MVC 6 with vNext: Do we still need the Global.asax?

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 ?

Do I still need the Global.asax ? Why has it been removed by default ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...