Home > other >  IIS Publish ASP.NET Core App Without Bringing Down IIS Website
IIS Publish ASP.NET Core App Without Bringing Down IIS Website

Time:06-09

Current Setup


We currently deploy our ASP.NET Core products to:

  • Windows Server 2016
  • Hosted on IIS Version 10.0.14393.0

We have a single "Site" with multiple applications under it. Each application uses its own application pool and is mapped to a different physical folder path location.

Each application is represented by its own source code ASP.NET Core Server project

IIS Structure

IIS Structure of child Apps in Site

The Problem


We use Jenkins for our CI/CD, and this cannot be changed. We have Powershell scripts to interact with IIS

There is no IIS command to stop an Application, only a Site, but we ideally do not want to bring down the site when publishing a new version of a single Application. We only want to bring down that specific Application.

We attempted this by stopping the WebAppPool associated with the application, and then waiting (2 minutes .. then 5 minutes). But even after that the application files are still locked.

We end up shutting down the WebAppPool and the Site to release the files so they can be replaced.

I know there has to be a better way to do this. How can we shut down an individual app, and prevent new requests from reaching it so we can replace the files and then restart it? All while the "SITE" and any other App under it not being updated is still running. I don't mind down time for the App being updated.

Update 6/8/2022

Found this: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/app-offline?view=aspnetcore-6.0

Going to see if this can solve my problem.

CodePudding user response:

Adding a file named app_offline.htm in the root folder of your application should force ASP.NET Core Module to shutdown the app and stop processing incoming requests. You should then be able to deploy new file with no impact on the the other applications.

CodePudding user response:

I highly recommend using web deploy with IIS. It is kind of a hassle to setup, but once configured it really works great.

If you publish this way, it will automatically do the following:

  • Pause incoming requests
  • Stop the old version of the application
  • Recycle the application pool
  • Start the new version of the application
  • Paused requests will be resumed to the new version of the application

This solution enables you to deploy new versions with no perceivable interruption to your service.

I have only used the publish menu from Visual Studio but it should be possible to make it work from a CI/CD script calling msbuild.exe as described here. (link descibes soultion for TeamCity but should be possible to adapt to Jenkins)

CodePudding user response:

I've previously had success with pointing the Site in IIS to a symlink. The symlink then in turn pointed to a folder that held the contents of the webpage.

Whenever I had to update the webpage, I would then create a new folder, lets call it webpage_date, then update the symlink and point it to the new folder. Lastly I recycled the AppPool that was responsible for the webpage.

So it would go:

symlink -> webpage_1

Put folder with updated webpage next to it, call it webpage_2. Point symlink to it:

symlink -> webpage_2

Then recycle AppPool.

This made it possible to have a pretty low downtime.

Powershell command to Restart-WebAppPool:

Restart-WebAppPool -Name "YourAppPool"

Restart-WebAppPool documentation

Symlinks can be created with

New-Item -ItemType SymbolicLink -Path .\link -Target .\Notice.txt

Powershell New-Item Symlink documentation

  • Related