I have some scheduled jobs that need to be run in the Application_Start but as far as I know, this method only get triggered after the first request. Is there anyway I can just auto startup the application after I stop and start the connection in IIS or stop/start/restart the site?
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
I. Install the Application Initialization Module
The application initialization module allows IIS to preemptively perform initialization tasks such as making the initial HTTP request to your application, or call your custom logic to perform whatever you desire to warm up your app.
I find it necessary to install the module even though the settings for making an application auto start and always running are there on IIS 10 which is the server I am using.
You can install the Application Initialization module via the Server Manager.
You can find the module under Server Roles -> Web Server -> Application Developer -> Application Initialization.
II. Configure the app pool
In IIS Manager, right click on the application pool under which the application runs and select “Advanced Settings”. Update the following values:
• Set the .NET CLR version to v4.0.
• Set start mode to “Always
Running”.
• Set Idle Time-Out (minutes) to 0.
III. Configure the IIS site
In IIS Manager, right click on the site for the application, select “Manage Website” -> “Advanced Settings” and set the “Preload Enabled” value to true.
Method 2
If you are on IIS 7.5, you can setup the application auto start, as you can see on this post on the ScottGu blog.
Basically, you have to add the startMode=”AlwaysRunning” attribute on the application host config file, in the app worker process entry.
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