Deployment on IIS using app_offline.htm

Deployment on IIS using app_offline.htm

A less destructive approach when deploying upgrades to a running application on IIS

·

2 min read

If you have a .NET Core application and need to deploy it to IIS via Web Deploy, then this might makes your life a little bit easier.

If,

  • The application pool is shared among applications. (You probably do not want to stop the whole app pool just for an application deployment, and affecting the other applications.)
  • You do not have the enough permission/clearance to make modification on settings to the hosting server.

When an ASP.NET Core application is running, it locks the assemblies that are in use, so if you perform deployment via Web Deploy while the application is running, you are likely to encounter errors, such as Publish failed to deploy.

This happens when you try to make changes to the files when some files are in use, or locked by an process.

Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'xxx.dll' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock
, or use the AppOffline rule handler for .Net applications on your next publish attempt.
Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.

App Offline file (app_offline.htm)

The file is used by the ASP.NET Core Module (ANCM) to shut down an application. If the file is detected in the root directory of an running application, the ANCM attempts to gracefully shut down the application and stop processing incoming requests.

When the file is present in the root directory, the ANCM responds to requests by sending back the context of the app_offline.htm. The file must be less than 4 GB.

Impact

If your company has a Service Level Agreement (SLA), then this approach might be not the best as it does not offer a zero downtime deployment.

Shortcoming

From what I know, Web Deploy does not place the file automatically into the root directory of the application while publishing.

Thus, you need direct access to the folder on the hosting server, add the app_offline.htm file into the root directory, deploy via Web Deploy then remove the app_offline.htm so that your application will restart.

Read More:

Taking Web Applications Offline with Web Deploy