Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused over global.asax?

I have a class called Global that derives from HttpApplication.

Oddly, I see a lot of methods inside Global that look like:

void Application_Start(object sender, EventArgs e)
{
}

The code is definitely executing inside this method, so the method is being called from somewhere, but where? The methods aren't marked overload?

Secondly, I derived a class from Global, let's call it GlobalFoo.

Again, if I create a method called Application_Start() it will get called inside my derived class, otherwise nothing that's in Global will get called so I might as well be deriving from an empty class.

Can anyone offer any advice? Am I missing some fundamental part of ASP.NET?

like image 234
maxp Avatar asked Oct 12 '10 11:10

maxp


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.

What is Application_Start in global ASAX?

The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.

Why is global ASAX is used?

Global. asax is the asp.net application file. It is an optional file that handles events raised by ASP.NET or by HttpModules. Mostly used for application and session start/end events and for global error handling.

Does .NET core have global ASAX?

Global. ASP.NET Core introduced a new mechanism for bootstrapping an app. The entry point for ASP.NET applications is the Global. asax file. Tasks such as route configuration and filter and area registrations are handled in the Global.


1 Answers

so the method is being called from somewhere, but where?

This functions are called from the Application Pool (from each pool that you have assign), to signal start-up/end events of your application and help your with initializations.

Every pool that is assign to run your web application runs those functions.

asp.net is helping you create different objects/code external or not that can run together, and that's why you see that all of your registered code run. Its a help to create more than one "start up" routines that do different thinks.

This is an example, this module just check the secure protocol by him self... and you do not need to change anything on your code, just register it.

like image 86
Aristos Avatar answered Sep 23 '22 17:09

Aristos