Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does PreApplicationStartMethod actually get triggered to run?

When using the WebActivator PreApplicationStart method, what actually triggers the methods bound to this to be run? When IIS7 has started the App Pool? When the first request is made to the webserver? Something else? If you have the answer, could you please also provide a reference to where you got this information?

Does any of this change in IIS 7.5?

like image 851
Eli Avatar asked May 10 '11 20:05

Eli


2 Answers

WebActivator PreApplicationStart actually relies on ASP.NET PreApplicationStartMethodAttribute (see this link to see how web activator works).

PreApplicationStartMethodAttribute works when ASP.NET runtime starts up the application and the code runs early in the pipeline even before app_start event gets fired. So to answer your question, trigger would happen when first request is made to the web server (which will in turn kicks in application start up).

Note that trigger is related to ASP.NET app start and not with app pool. Your app pool might be running because of some other application (can be non ASP.NET app) but when first request comes for the ASP.NET app, this trigger would happen (for particular app) because application gets started.

If you are using auto-start feature then IIS will re-start your application on your app pool recycle and thus PreApplicationStart will get triggered.

like image 158
VinayC Avatar answered Nov 07 '22 14:11

VinayC


A small supplement to @VinayC's answer: if you add a breakpoint in your PreApplicationStartMehod and debug your web application, you may see it being invoked on every request. I easily confirmed that this isn't the usual behavior by writing to a log file in my PreApplicationStartMethod. When not attached to the debugger, this method does not run on every request.

like image 35
mbaynton Avatar answered Nov 07 '22 14:11

mbaynton