Hi @kennywangjin ,
Thanks for your question. IIS has always had a feature using a special file called
app_offline.htm to temporarily shut down the Application Host and start it back up but without loading any of the modules and only serving the
app_offline.htm file which displays a busy message. Effectively this keeps your site from running any code while the file exists in the root folder of the site. When the file gets deleted the site starts back up.
You can create this static file containing some HTML and as soon as that file is placed in the folder the current running application is shutdown and any new requests only see the
The idea is that you can plop this file into the application's root folder, which shuts down the app. You can then publish your application replacing all files as needed then remove
app_offline.htm to restart the app.
This works fine, but it's hard to automate this process unless you have direct access to the site or you are running an explicit deploy process on the server. It certainly doesn't help with the IIS Publish feature in Visual Studio by default.
By default WebDeploy doesn't place an
app_offline.htm file into the folder while publishing which is really bad form.
Publish Profile Setting: EnableMsDeployAppOffline
Luckily there's a simple solution via a newish switch available in MsDeploy that was added in Web Deploy 3.x.
There's now a
EnableMsDeployAppOffline value that you can add to the publish profile like this:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
When set to true this setting automatically has MsWebDeploy create an
app_offline.htm file which unloads the running application, publishes files, then removes that file.
It's a very simple fix that automatically handles copying a generic
app_offline.htm, publishing files, then removing the file. Sadly it's not the default setting and the switch is somewhat obscure that is not easily discoverable. With that switch in place and set to true, publish now works to properly publish files to a running site.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread.