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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0