Application Lifecycle
Dynamicweb has a lifecycle within the IIS, which this document will outline. The headings for these overall lifecycle states are the following:
- Application_Start
- Application_BeginRequest
- Ensure Dynamicweb is started
- Application_OnPreRequestHandlerExecute
- Application_EndRequest
- Application_Error
- Application_End
The naming is purposely similar to the ASP.NET Application Life Cycle Overview for IIS 7.0 (https://msdn.microsoft.com/en-us/library/bb470252.aspx). The formatting is present to illustrate when a state has a corresponding end-state.
Of the above states, 01 to 04 are of particular interest, as they expose notifications such as BeforeDynamicwebStart which you can hook into in your custom code.
Application_Start
This event fires once every time the application is started, resulting in the following:
- Notification Manager is initialized
- BeforeStart notification fires
- MVC is initialized (Rank = -80)
- AfterStart notification fires
- ExecutionTable initalized (Rank = -50)
Application_BeginRequest
This event fires once for every request to a frontend or backend page, resulting in the following:
- BeforeBeginRequest notification fires
- Ensures Dynamicweb.Context is available (Rank = -100)
- Timestamp request (e.g. used for debug-information)
- Ensure Dynamicweb is started
- AfterBeginRequest notification fires
Ensure Dynamicweb is started checks to see if Dynamicweb is initialized.
It is guaranteed to only execute if AfterDynamicwebStart has not been fired.
- BeforeDynamicwebStart notification fires
- Ensures Dynamicweb.Context is available with request (Rank = -100)
- Examine database and global settings
- Redirect to setup wizard if needed
- Setup TaskManager
- Setup Log
- Check/setup license
- Run update scripts
- Setup MEF and Scheduled Tasks
- Initialize Modules
- Initialize ItemManager
- AfterDynamicwebStart notification fires
Application_OnPreRequestHandlerExecute
This event handles user authentication/login.
- BeforePreRequestHandlerExecute notification fires
- Ensures Dynamicweb.Context is available with session (Rank = -100)
- User is authenticated
- AfterPreRequestHandlerExecute notification fires
Application_EndRequest
- Write dbstat if requested
- Write debug information if requested
- Write dbcount if requested