winserver 2022 IIS lock file when deploying web application using webdeploy (appoffline file already generated):

kennywangjin 1 Reputation point
2022-07-14T00:41:13.91+00:00

When deploying web application using webdeploy, IIS in windows server 2022 locks file and prevents deploying. appoffline.html file already generated. After several minutes and several times retries, I can complete deploying.
IIS in windows server 2019 or earlier versions have no such errors.
Is it a bug of IIS in windows server 2022? any patches?

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yurong Dai-MSFT 2,811 Reputation points Microsoft Vendor
    2022-07-14T05:47:19.923+00:00

    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 app_offline.htm page.

    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">  
        <PropertyGroup>  
        	<WebPublishMethod>MSDeploy</WebPublishMethod>  
            ...  
            <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>  
        </PropertyGroup>  
    </Project>  
    

    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.

    Best regards,
    Yurong Dai