How to update ASP.NET Core files without stop IIS Application & Pool in .NET5? - asp.net-core

Every time need to stop the IIS Application or Pool to update
or system will show The action can't be completed becacuse the file is open in w3wp.exe
I expect like asp.net or mvc, you don't need to stop IIS to update.
Right now my way, I drop a file called app_offline.htm (case sensitive) to my application folder. Let IIS auto stop my application then I update it
From this article iis - How can I update ASP.NET Core app over an existing/running site without stopping the web server? - Stack Overflow

If we use asp.net core, we cannot achieve non-stop update projects.
When IIS is running your website process, if a request comes in at this time, the dll/exe file will be locked. If an update item is released at this time, the dll/exe cannot be replaced successfully and an error will be reported.
As for why asp.net can achieve uninterrupted updates, because the difference between core and asp.net is that asp.net applications are completely deployed in IIS, while asp.net core uses IIS as a proxy server. We can think of the core application as a console application. So to update the asp.net core application must stop IIS.
The solution I thought of was to provide a transition site.

I found solution for asp.net core but I am not quite happy with it. Maybe it would be fine for big project with lots of files to copy.
upload app_offline.htm with site update message
change appPool to other i.e DefaultAppPool
delete web.config
stop appPool for my app (this part takes literally minutes)
publish new version
change appPool back to my app and start it
restore web.config
Useful Windows Commands:
%SYSTEMROOT%\System32\inetsrv\appcmd list app
%SYSTEMROOT%\System32\inetsrv\appcmd set app /app.name:"[MyAppName/]" /applicationPool:DefaultAppPool
%SYSTEMROOT%\System32\inetsrv\appcmd set app /app.name:"[MyAppName/]" /applicationPool:[MyAppPool]
%SYSTEMROOT%\System32\inetsrv\appcmd stop apppool /apppool.name:"[MyAppPool]"
%SYSTEMROOT%\System32\inetsrv\appcmd start apppool /apppool.name:"[MyAppPool]"

Related

Run exe file alongside .NET Core Web Application

I have an executable file which I would like to run alongside a .NET Core web application. It needs to start when the web application loads and will continuously run until the web application ends. I also need to be able to check if the executable file is still running through the UI, and have an option to start, stop or restart.
I have done a bit of googling already on this and all that keeps returning is examples where the exe file is expected to end at some point, not anything that continuously runs.
Any pointers in the right direction would be great.
Andy's comment is correct. It's recommended to using Background tasks with hosted services in ASP.NET Core.
And you also can use signalr to record the status of your service. You can start, stop by using StartAsync and StopAsync. And it's impossible to restart. The background service was launched with asp.net core.
For more details, you can check the blog:
Communicate the status of a background job with SignalR

How is it possible to overwrite a dll file in web root folder while IIS is running the app?

I want to overwrite a file in the web root directory of an ASP.NET Core application running on IIS. I copy the file remotely but it say that the file is under the use and cannot overwrite. How can I copy dll files remotely while ISS is running?
If the App within IIS can be set offline briefly, you can use app_offline.htm
The App Offline file (app_offline.htm) is used by the ASP.NET Core Module to shut down an app.
If a file with the name app_offline.htm is detected in the root directory of an app, the ASP.NET Core Module attempts to gracefully shut down the app and stop processing incoming requests. If the app is still running after the number of seconds defined in shutdownTimeLimit, the ASP.NET Core Module stops the running process.
Source: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/app-offline?view=aspnetcore-6.0
If the app needs to keep running the solution with Shadow Copies mentioned by Lex Li in the comments might be helpful.
Note: Shadow Copys are still experimental in .net 6. At the moment this feature still is experimental as far as I know. this discussion might be helpful:
https://github.com/dotnet/AspNetCore.Docs/issues/23733

How to update a running asp.net core application on Windows?

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?
A workaround For Windows with no down time and I am regularly using is:
Rename running .NET core application dll to filename.dll.backup
Upload the new .dll (web application is available and serving the requests while file is being uploaded)
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
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
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
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.

How to cause recompile of ASP.NET 5 RC 1 application in Azure

With previous pre-releases of ASP.NET 5, when an application was deployed to Azure and I edited the files inside approot (compiled ones, e.g. HomeController.cs), it would trigger a recompile of the site and my changes would be visible on the next request of the live site. This no longer happens with in RC1. I can trigger a recompile by touching web.config, but I was wondering if there was another way to signal that the application needed to be recompiled.
ASP.NET 5 natively doesn't have auto-restart features as ASP.NET previous had. In ASP.NET 5 this becomes the responsibility of the Web host - IIS in your case and if you use IIS you can use the old tricks like touching Web.Config to cause reload of an application.
Alternately you can run an external file monitoring utility on your server to trigger updates when files change but that's a bit more difficult to do if you're running on an Azure web site.

Deploy MVC 6 app in IIS

I'm using Visual Studio Express 2015RC and I created a simple MVC 6 application, but when I try to publish it I don't see the option to deploy it to IIS, I see the options Microsoft Azure Web App, Import and File System, I tried the File System but It looks like it is more for creating stand alone applications to be launched from a console, now, when debugging I can select IIS Express or the web command, there is no IIS option, so the question is, how can I deploy the MVC6 web application I created to IIS?
File System publish is actually exactly what you want; All DNX applications are stand-alone, whether for ASP.NET 5 or a console app.
When you publish to the File System, you get a few folders; the wwwroot (assuming you kept the default in your project.json) folder is where IIS should point. The web.config in that folder is generated for you automatically assuming you keep everything else where it is.
For what it's worth, the official documentation will probably be here, once it's written. Also, on Stack Overflow, ASP.NET 5 project hosting on IIS probably has some useful information, though it looks like it's a bit out of date at the moment.