9

I have a Asp.Net Core MVC application running on Windows Server 2008 R2 with IIS. But every time I update this application, I need to manually stop the applicationPool in IIS, and restart the applicationPool after I finish updating the app. Otherwise it will tel me "the xxx.dll is in use by other progress".

Is there any way to make this process easier?

John
  • 716
  • 1
  • 7
  • 24

4 Answers4

4

A workaround For Windows with no down time and I am regularly using is:

  1. Rename running .NET core application dll to filename.dll.backup
  2. Upload the new .dll (web application is available and serving the requests while file is being uploaded)
  3. Once upload is complete recycle the Application Pool. Either Requires RDP Access to server or function to recycle application pool in your hosting control panel.

IIS overlaps the app pool when recycling so there usually isn’t any downtime during a recycle. So requests still come in without every knowing the app pool has been recycled and the requests are served seamlessly with no downtime.

I am still searching for more better method than this..!! :)

January 2022 - for Linux

For Linux, we use Openresty nginx with Lua script to hold (sleep) incoming requests for few seconds until the service running .NET Core or .NET 5 or .Net 6 application restarts and then we release the threads we had hold.

Refer: https://github.com/basecamp/intermission

Bharat Vasant
  • 850
  • 3
  • 12
  • 46
  • how can you rename your dll when your app is running ? unless your app is not running at all – John Mar 20 '21 at 13:48
  • I am doing this on Windows. Which OS you are talking about? Since renaming file keeps file handle valid. Have you tested this and faced any problem or not able to rename running dll or exe ?? – Bharat Vasant Mar 22 '21 at 05:51
3

Finally I found my anwser:
I just need add a file named app_offline.htm to the IIS web root(not your project wwwroot folder), and remove it after you replace all of your file. due to this issue you may need try both App_Offline.htm or app_offline.htm .

and this will allow you to use FTP client to update

John
  • 716
  • 1
  • 7
  • 24
  • If you add that file to your web folder, the application will be offline and user will see only that html. I don't think that is a solution. On the other hand, you can modify your web.config without change any value and the application will restart but sessions will be lost. – daniherculano Jun 07 '19 at 07:22
  • @daniherculano change the `web.config` will also case your web application stop, but won't stop your site to start again, so if u are updateing a website, and there's a people visit your site, it's not a reliable solution (ur app may start before u replace the file), the `app_offline.htm` will block you site to start until you remove it (and you can add a small script to detect is your update done. for example using `setInterval` to check the state code is 503 ) . so it's a better solution when you have large number of visitors or using a script to update ur site – John Jun 09 '19 at 01:07
1

Opening the web.config file in an editor and saving it will cause the web application to reload, even if you don't change anything. All DLLs should be replaceable, until a user hits the site, causing the web application to start again. I sometimes use that as a workaround.

A more full fledged solution would be to use Web Deploy, either through Visual Studio or by command line. This can take a litte while to set up, but offers more automation.

https://learn.microsoft.com/en-us/aspnet/core/publishing/iis#deploy-the-application-1

  • Is there any articles about how to use web Deploy packages? what i need to do on the server ? – John May 16 '17 at 09:17
  • Here is an article on how to install it on the server: https://learn.microsoft.com/en-us/iis/install/installing-publishing-technologies/installing-and-configuring-web-deploy-on-iis-80-or-later After you have it installed, you can right-click on your solution in visual studio on press publish and import the publish profile from the previous step. – Henning Weiss May 23 '17 at 09:04
  • I current not test this on a win server , I test on my client windows 7, and I use `web deploy package` , it still can not make the web site off even when I set the set 'offline rule' to enable. :( – John May 25 '17 at 03:15
  • @John if you use out of process, that the shutdown of your application may take more time than the web deploy need(and more than retry time), normally, your app will have 5s to complete shutdown process and exit , but there may take long than 15s (or even fail the exit process), in such case , web deploy try 5 time and each to wait 1s or 2s, and since your app is still runing (not finish exit) and your update will fail. – John Mar 29 '21 at 08:10
  • @John and please try directly using web deploy instead of web deploy package , – John Mar 29 '21 at 08:11
0

There is no way to hotswap in place DLL's.

Your best bet is to deploy to a new folder each time (For example a versioned folder), and change the website directory in IIS once you have fully copied your website onto the server.

MindingData
  • 11,924
  • 6
  • 49
  • 68
  • it still need to use IIS Console , and copy to a new folder i will lose the images that I uploaded. Is there a *script* to stop IIS app pool ,copy the files and start IIS app pool – John May 15 '17 at 01:10
  • Doing this you will lose open sessions – daniherculano Jun 07 '19 at 07:27