Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 814
Bellash Avatar asked Jul 13 '14 00:07

Bellash


People also ask

Is global ASAX mandatory in MVC?

We know that Global. asax is an optional file to handle Application level event in ASP.NET application.

Is global ASAX mandatory?

They defined methods for a single class, application class. They are optional, but a web application has no more than one global. asax file.

Can we run ASP.NET application without global ASAX file?

asax is not required by ASP.NET for a website to run. It is, however, very useful for application-level functionality (like unhandled exception logging). Save this answer.

What is the use of global ASAX in MVC?

The Global. asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event. The file in Listing 1 contains the default Global.


1 Answers

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.

like image 108
Erik Funkenbusch Avatar answered Oct 14 '22 12:10

Erik Funkenbusch