How to deploy an ASP.NET Application with zero downtime

后端 未结 11 1361
日久生厌
日久生厌 2020-11-28 00:38

To deploy a new version of our website we do the following:

  1. Zip up the new code, and upload it to the server.
  2. On the live server, delete all the live
11条回答
  •  温柔的废话
    2020-11-28 01:06

    Using Microsoft.Web.Administration's ServerManager class you can develop your own deployment agent.

    The trick is to change the PhysicalPath of the VirtualDirectory, which results in an online atomic switch between old and new web apps.

    Be aware that this can result in old and new AppDomains executing in parallel!

    The problem is how to synchronize changes to databases etc.

    By polling for the existence of AppDomains with old or new PhysicalPaths it is possible to detect when the old AppDomain(s) have terminated, and if the new AppDomain(s) have started up.

    To force an AppDomain to start you must make an HTTP request (IIS 7.5 supports Autostart feature)

    Now you need a way to block requests for the new AppDomain. I use a named mutex - which is created and owned by the deployment agent, waited on by the Application_Start of the new web app, and then released by the deployment agent once the database updates have been made.

    (I use a marker file in the web app to enable the mutex wait behaviour) Once the new web app is running I delete the marker file.

提交回复
热议问题