IIS restarts suspended aplications after configuration change - asp.net

I have encountered a (mis?)behavior of IIS/ASP.NET related to app pool suspension (Idle Worker Process Page-Out), and I can't find documentation about it. When an ASP.NET app (.NET Framework 4.8) in IIS (10.0) is suspended, and then a change is made to IIS configuration, the next time the app is accessed, it restarts (new AppDomain in same w3wp process).
It doesn't matter What is changed in IIS (appcmd add apppool, appcmd add app, etc.). Even touching applicationhost.config (changing LastWriteTime without content change) is enought to fire a restart. To be clear, the restart only happens if the app is SUSPENDED when IIS configuration is changed, and not if the app is live.
We have a lot of apps in the same IIS server, with frequent app deployments, and each time a deployment is made, all the suspended apps are affected (next user must wait the restart time). This renders useless the suspension mechanism. ¿Is this restart behavior by design or it's a bug? ¿Is there a way to prevent it?

Related

How can I determine why IIS is recycling my app in shared hosting?

I've deployed an ASP.NET MVC app (on runtime 4.5.2), which works in development, and also on Azure.
But when deployed to my actual production environment, which is shared hosting on IIS 8.5, I get frequent app recycles, usually every few minutes or after only two or three requests! Sometimes the app bombs so badly, I need to ask them to restart it manually because it doesn't restart automatically.
The only thing I've done which is maybe non-standard, is I've disabled session state in web.config, because I don't use session.
In Application_Error I log errors. In Application_End I log HostingEnvironment.ShutdownReason, which is always equal to HostingEnvironment, which isn't helpful, because all that means is "The hosting environment shut down the application domain."
They refuse to let me see their server logs.
My app is (I think) bug-free, and as I stated above, it works perfectly on Azure. So there is a problem somewhere between how IIS is configured, and my app behaves.
What can I do to drill down into this problem?

How do you restart an asp.net web forms application?

I am getting this error after publishing my application:
The directory '/App_GlobalResources/' is not allowed because the application is precompiled.
My googling has yielded many recommendations to "restart my application" only I have no idea how to do this.
To restart your application you can open web.config in an editor, add a space somewhere, and save it. Please be aware that if you are using in-process session state the application pool will recycle, causing session state to be lost. However, this method has the benefit of not affecting web applications in other application pools.
If you want only this application to be affected, you could place it in its own application pool, or use one of the other session-state modes. Session State Modes
Refresh your website and Restart your application pool from IIS.
If you're developing locally, open a command prompt and type iisreset If you do this on a production machine you're going to take ALL the sites on that machine down during the reset. It's usually quick, but some sites can't have downtime during peak hours...
On a server, stop the app and app pool, then start them again.

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.

iis7 application pool hanging

I have a .net 4.0 website that was running on physical Windows server 2003 boxes on IIS6 32bit just fine. We have migrated to new virtual servers running Windows Server 2008 32 bit with IIS7. The application pool is running in classic mode.
Since the move, I at random get a situation where the application hangs. The request queue rockets and then I get 503 errors. If the application pool is recycled, then the error goes away till the next time it occurs.
There are no entries in the event logs relating to it except that it notes when the application pool took to long to shut down during the recycle process. I have reporting in my .net application that logs to a DB and sends me errors but it sends me nothing when this application is hanging.
What tools can I use to diagnose the problem and figure out what is causing it?
In opinion, whatever the structure of application is, if you're pretty sure that there is no bug, changing sort of properties on the application pool might solve the problem.
First on the 'Advanced Settings...' menu of the application pool change the 'Enable 32-Bit Applications' to the relevant value. If the platform used for building application is x86 then the value should be 'True'.
Second if your application demands to access disk resources, also you should the relevant security context for running the application pool in the 'Identity' property. The identity should access all the directories that your application wants to change or list.
After doing all the things, in case the problem existed, you should let me know about the platform of your application. Is it .NET or ISAPI?
Cheers

What does 'IISReset' do?

On IIS 6, what does an IIS reset do?
Please compare to recycling an app pool and stopping and starting an ASP.NET web site.
If you replace a DLL or edit/replace the web.config on an ASP.NET web site is that the same as stopping and starting that web site?
IISReset stops and restarts the entire web server (including non-ASP.NET apps)
Recycling an app pool will only affect applications running in that app pool.
Editing the web.config in a web application only affects that web application (recycles just that app).
Editing the machine.config on the machine will recycle all app pools running.
IIS will monitor the /bin directory of your application. Whenever a change is detected in those dlls, it will recycle the app and re-load those new dlls. It also monitors the web.config & machine.config in the same way and performs the same action for the applicable apps.
IISReset restarts the entire webserver (including all associated sites). If you're just looking to reset a single ASP.NET website, you should just recycle that AppDomain.
The most common way to reset an ASP.NET website is to edit the web.config file, but you can also create an admin page with the following:
public partial class Recycle : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpRuntime.UnloadAppDomain();
}
}
Here's a blog post I wrote with more info: Avoid IISRESET in ASP.NET Applications
It operates on the whole IIS process tree, as opposed to just your application pools.
C:\>iisreset /?
IISRESET.EXE (c) Microsoft Corp. 1998-1999
Usage:
iisreset [computername]
/RESTART Stop and then restart all Internet services.
/START Start all Internet services.
/STOP Stop all Internet services.
/REBOOT Reboot the computer.
/REBOOTONERROR Reboot the computer if an error occurs when starting,
stopping, or restarting Internet services.
/NOFORCE Do not forcefully terminate Internet services if
attempting to stop them gracefully fails.
/TIMEOUT:val Specify the timeout value ( in seconds ) to wait for
a successful stop of Internet services. On expiration
of this timeout the computer can be rebooted if
the /REBOOTONERROR parameter is specified.
The default value is 20s for restart, 60s for stop,
and 0s for reboot.
/STATUS Display the status of all Internet services.
/ENABLE Enable restarting of Internet Services
on the local system.
/DISABLE Disable restarting of Internet Services
on the local system.
Application Pool recycling restarts the w3wp.exe process for that application pool, hence it will only affect web sites running in that application pool.
IISReset restarts ALL w3wp.exe processes and any other IIS related service, i.e. the NNTP or FTP Service.
I think changing web.config or /bin does not recycle the whole application pool, but I'm not sure on that.
It stops and starts the services that IIS consists of.
You can think of it as closing the relevant program and starting it up again.
Editing the web.config file or updating a DLL in the bin folder just recycles the worker process for that application, not the whole pool.
IISReset restarts the entire webserver (including all associated sites). If you're just looking to reset a single ASP.NET website, you should just recycle that Application Domain.
When you change an ASP.NET website's configuration file, it restarts the application to reflect the changes...
When you do an IIS reset, that restarts all applications running on that IIS instance.
Here what's technet has to say about iisreset
You might need to restart Internet Information Services (IIS) before certain configuration changes take effect or when applications become unavailable. Restarting IIS is the same as first stopping IIS, and then starting it again, except it is accomplished with a single command.

Resources