I have the global.asax
which extends from a custom class I created, called MvcApplication
which extends from System.Web.HttpApplication
.
In it's constructor, it logs application start as per below:
protected MvcApplicationGeneral()
{
_log.Info("logApplicationStartToTextFile");
}
When I went to look in the log file, this seems to be called A LOT of times, not just once per application start. I placed another log entry in Application_Start
and that seems to be called only once. Is the Global.asax
class instantiated per request, or much more frequently than just once per application?
Multiple intances of HttpAppliction objects are created and pooled to process the requests.in the lifecycle of an asp.net application. yes Application_Start will be called only once.
refer http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle
excerpt: Once all the core ASP.NET objects are created, ‘HttpApplication’ object is created to serve the request. In case you have a ‘global.asax’ file in your system, then the object of the ‘global.asax’ file will be created. Please note global.asax file inherits from ‘HttpApplication’ class. Note: The first time an ASP.NET page is attached to an application, a new instance of ‘HttpApplication’ is created. Said and done to maximize performance, HttpApplication instances might be reused for multiple requests.