IIS 6.1 - Always running web site with Hangfire for background jobs - asp.net

I want to create an ASP.NET web site on IIS 6.1 (cannot be changed), that does not recycle nor shuts down. I want it to always be running and never be down not even for a second.
Are there any built-in features that can help me achieve this?
(I cannot create a Windows Service. I need a web site.)
The workaround and less preferable solution would be creating a regular web site and creating a windows scheduled task that calls a function in that web site in a fixed interval so it never recycles.
Do you know if IIS 7.* or IIS 8 support such a functionality?
** EDIT
It will be a web site running Hangfire for the background tasks.
Of course the Windows Service + Hangfire solution is better but because the lack of time and to keep it simple for our developers it is easier for us to maintain a web site which runs background jobs.

Depending on the framework, framework version, etc there might be different configurations that need to be accounted.
The best approach would be to check the official docs that asses this exact problem.
For example, if you build a .NET Core app, the steps for keeping an app alive are:
Managed pipeline mode: Integrated
Set start mode to “Always Running”.
Set Idle Time-Out (minutes) to 0.
Set Preload Enabled = True
Go to the Configuration Editor on your app, and navigate to system.webServer/applicationInitialization. Set the following settings:
doAppInitAfterRestart: True
Open up the Collection… ellipsis. On the next window, click Add and enter the following:
hostName: {URL host for your Hangfire application}
initializationPage: {path for your Hangfire dashboard, like /hangfire}

Under the app pool set the idleTimeout to 0. That will disable idle timeout recycling.

Related

Configuring IIS (v7.5) for ASP.NET application

If I have IIS 7.5 or newer, and I want to make sure my ASP.NET application hosted on IIS is as responsive and available as possible, one thing I do is usually setting the Start Automatically advanced setting for the app pool in IIS to true:
My question that I'm scratching my head about (and can't seem to find a definitive answer for) is: if the Start Automatically = true is set, does the Idle Time-out (minutes) setting have any effect?
As far as I understand, the Start Automatically setting makes sure the app pool is always up and running and available - so doesn't that kinda "kill off" the concept of an "idle timeout" ?
Start automatically as the description reveals, only enables the application pool upon creation or when IIS restarts. It has nothing to do with the other setting.

How to properly autostart an asp.net application in IIS10

I'm trying to get my ASP.NET application to automatically start whenever the application pool is running.
As per the lots and lots of references online I have already done the following:
Set the Application Pool to StartMode=AlwaysRunning
Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
Install the Application Initialization feature to the Windows installation
Add the <applicationInitialization> node to the web.config's <system.webServer> node
The web application is based on Owin and has a simple log4net logging statement in it's Startup.Configuration() method. Now when restarting IIS I see that the w3svc.exe process is running, so I know the StartMode=AlwaysRunning is working. There are however no logging messages in the log file.
Navigating to any url (even a nonexisting one) in the application will start the app and add the log line.
Because of the actual work that's done in the startup of the application I really want the application to truly preload, but I seem to be unable to get it done.
Searching this site I have unfortunately not been able to find a solution.
Thanks in advance.
To answer my own question for future generations, it seems I was on the right track. To get the application to start in IIS10 (and I assume in IIS 8 as well) you only need the following three steps:
Set the Application Pool to StartMode=AlwaysRunning to make sure the w3svc.exe process is always running for the App Pool.
Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
Install the Application Initialization feature to the Windows installation as per the instructions here.
One important thing to note is that if the Application Initialization task was not previously installed on the machine you must reboot the machine. This is what I missed the last time which led to quite some time wasted looking for other things :(
Anyway, setting up those three things will cause the app to actually go through it's initialization, which is especially useful if you want to setup some scheduling task (ea using the Quartz NuGet package).
Note by the way that if you setup auto initialization like above, the application will also automatically start after the shutdown timeout has expired and on application pool recycles.

Recycle and reload application pool on IIS7

Is there a way to recycle and afterwards reload an application pool?
My problem has been slow performance when logging in to my web application. I found out that the "Idle Time-out(minutes)" was sat to 20 by default. This caused the application to terminate when idle so that it can start up again on the next visit. After searching the web i found out that this value could be sat to 0 so it won't terminate. However, the first visit after recycling, an app pool have to create a new w3wp.exe worker process which is slow because the app pool needs to be created, ASP.NET or another framework needs to be loaded, and then the application needs to be loaded. Source right here
This means that every time the app recycles, the first visitor have to wait longer then the other visitors when logging in, doing some stuff and log out.
The web application is using the ISS from Dynamics AX 2009.
Sorry I thought you are working on IIS 7.5
But there was a beta for this in IIS7 actually.
I think you are looking something along the lines of this
A warmup module for IIS 7.5
"IIS Application Initialization for IIS 7.5 enables website administrators to improve the responsiveness of their Web sites by loading the Web applications before the first request arrives. By proactively loading and initializing all the dependencies such as database connections, compilation of ASP.NET code, and loading of modules, IT Professionals can ensure their Web sites are responsive at all times even if their Web sites use a custom request pipeline or if the Application Pool is recycled. While an application is being initialized, IIS can also be configured to return an alternate response such as static content as a placeholder or "splash page" until an application has completed its initialization tasks."
Download Link
http://www.iis.net/downloads/microsoft/application-initialization
And also have a look at this; which basically talks about using warm up classes which comes with ASPNET 4
http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx
Checkout the suspend option.
IIS now has
Idle Time-out Action : Suspend setting
Suspending is just freezes the process and it is much more efficient than the destroying the process. Because it uses the same process and does not create another one after waking up.

IIS App Pool/Restart and ASP.NET

We are using IIS7 to host an asp.net web-based application.
In this environment administrators and developers can deploy code to the application on a regular basis.
The new code or app goes as a DLL to the ASP.NET bin folder. Upon deployment of the new DLL, IIS restarts the process, impacting (slowing down) all online users.
Is there a way to configure IIS to run the process in the background and once ready make the switch from old state into new without impacting the users?!
Thanks in advance for your feedback!
IIS already does this, that's what recycling is all about. IT's loading the DLL's while the old version of the application is still running. only after this is completed the recycling is complete.
However loading the DLL's is only part of getting web applications ready, there might also be initial loads like loading/caching the user db etc.
These actions are not part of the recycle process, they happen after all DLL's reloaded and the recycling is already completed.
A while back I ran into this issue with an application that had a huge startup time due to heavy db activity/caching during startup. So I was interested if there is some functionality that allows us to execute code before the recycle is marked as completed, so that the application is first considered recycled when everything is ready to run. Basically what I wanted is some kind of staging functionality.
I was in contact with the IIS team regarding this issue, sadly they told me that no such functionality exists, nor is it planned.
To solve this you could try do the following:
Use alternating deploys:
You setup 2 Websites with separate application pools. One of them is the LIVE website the other one is the STAGED website. If you want to deploy changed you simply deploy to the STAGED website. After everything is loaded/cached etc. you switch the URL settings of the web applications to reroute incoming requests from the LIVE to the STAGED one. So the LIVE one becomes the new STAGED and the other way around. The next deploy would then go to the new STAGED again and so on.
UPDATE
Apparently they have created a IIS Module that provides this functionality by now:
IIS Application Warm-Up Module for IIS 7.5
The IIS team has released the first beta test version of the
Application Warm-Up Module for IIS 7.5. This makes warming up your
applications even easier than previously described. Instead of writing
custom code, you specify the URLs of resources to execute before the
Web application accepts requests from the network. This warm-up occurs
during startup of the IIS service (if you configured the IIS
application pool as AlwaysRunning) and when an IIS worker process
recycles. During recycle, the old IIS worker process continues to
execute requests until the newly spawned worker process is fully
warmed up, so that applications experience no interruptions or other
issues due to unprimed caches. Note that this module works with any
version of ASP.NET, starting with version 2.0.
For more information, see Application Warm-Up on the IIS.net Web site.
For a walkthrough that illustrates how to use the warm-up feature, see
Getting Started with the IIS 7.5 Application Warm-Up Module on the
IIS.net Web site.
See:
http://www.asp.net/whitepapers/aspnet4
If you use ASP.NET 4 Auto Start feature:
You can still choose to auto-recycle the worker processes from time to
time. When you do that, though, the app will immediately restart and
your warm up code will execute (unlike today - where you have to wait
for the next request to-do that).
The main difference between Warm Up and Auto Start feature is that the Warm Up Module is part of the recycling process. Rather than blocking the application for requests, while running the init code.
Only thing you get by using the Auto Start feature is that you don't have to wait for a user to hit the page, which does not help your case.
See the Gu's blog post:
http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx
UPDATE 2:
Sadly the Warmup Module has been discontinued for IIS 7/7.5:
http://forums.iis.net/t/1176740.aspx
It will be part of IIS8 though (It's now called Application Initialization Module):
http://weblogs.asp.net/owscott/archive/2012/03/01/what-s-new-in-iis-8.aspx
UPDATE 3:
As pointed out in the comments the Warmup Module resurfaced for IIS 7.5 as Application Initialization Module for IIS 7.5 after IIS 8 was released:
http://www.iis.net/downloads/microsoft/application-initialization
The first part of ntziolis answer is a wee bit inaccurate. The worker process isn't being recycled or restarted, it just keeps running. If this were the case, then in shared pool environments you would have sites knocked out every time a new one was deployed.
When you deploy a new ASP.NET application it's the site's "Application Domain" within the worker process is torn down, not the pool process.
In addition pool recycling is a completely separate concept to deployment
At this point in time in the commercial life of ASP.NET, during a deployment, a site will be in an inconsistent state until all of the site is deployed. There is still no good story about this from Microsoft at this time for single site on a single server deployments.
This is why ASP.NET has the special App_Offline.htm page. It's there so you can enable that page, deploy and then turn it off.
The second part of ntziolis answer is nearly correct but you don't need two sites or two application pools. You just need two file system folders that switch between being the physical folders for the site...if you're on a single server and not behind a load balancer or ARR.
If your sites were on a web server behind a load-balancer or ARR then having two different sites would make sense, you could route requests from one site to the other and round-robin on each deploy.
Obviously if there is a large amount of user generated content (uploaded files and the like) then you'd map a virtual directory in your site to a common location for this data.
In larger scale deployments where your app is running across (for example) a load-balanced environment you can do more sophisticated deployments.
For related questions please see:
How Do I deploy an application to IIS while that web application is running
Publishing/uploading new DLL to IIS: website goes down whilst uploading
Is smooth deployment possible with componentized ASP.NET MVC apps?

Does asp.net setting affect classic asp (IIS 6 settings)

My company has some classic asp sites and developing new sites in asp.net, and everytime we create a new site in IIS 6 all the sites go down for a couple of seconds. So I'm thinking of changing the default value of the ASP.NET version to 2.x since that is what we're developing and I'm wondinger if these settings somehow affect the classic asp sites that are running on same IIS.
All of them are asp.net 1.1 versioned right now but we have to get around this all-sites-down everytime we add a new site to IIS.
Any warnings? Anything I need to know etc?
Thanks a bunch.
All sites reset when you change the version of a site. Therefore, it is a good idea to change the default to the one you add the most.
The default setting will not affect any existing sites, .net, classic or otherwise.
The only issues you may have is that you cannot run a 1.1 virtual app within a 2.0 site.
Also, you cannot run different versions in the same app pool. Therefore you should change the default app pool at the same as changing the default version.
As an aside, I have read of some command line options and other setting that mean you can change the version of a site without causing all of iis to reset. However, I have not managed to do this personally.
Running a classic site along site a .Net site in the same app pool should be fine and you shouldnt see any down time in the IIS when you upload a new version to the server.
You will find the server pause for a few seconds if you change the config of any app pool or if you change over the .Net version that is running in a site, all sites running in that app pool will be reset as the app pool resets.
My recomendation would be to create 2 App pools one for your new .Net 2.0 sites and one for the old classic sites, this will also help out if you are undergoing development as although unlikely it is possable to write code to complete crash the app pool.
The only thing to remembger is that each app pool as a small memory overhead about 3-5MB so if you nmake an app pool for each site and host a large number of site you can very quickly run out of RAM.

Resources