Run exe file alongside .NET Core Web Application - asp.net-core

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

Related

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 ASP.NET Core files without stop IIS Application & Pool in .NET5?

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]"

Howto create an windows 10 application which starts a Self-Hosted website without IIS

I want to create a small windows 10 application where the user can start and add a single file (f.e. via drag and drop0. This file can then be downloaded in the local network as long as the application remains open.
I am now looking for the best way to do this, without using IIS. I have no idea where to start so I would appreciate any input. As far as I can tell .Net Core with Kestrel is a good way to go.
Since you want to have Drag-and-Drop functionality, you'll either want to accept a file dropped onto an .exe file, or have a Windows Forms or WPF app that can accept a file drop.
Either way, you can start an ASP.NET Core WebHost with Kestrel enabled from within any of these solutions, as long as it is running on a thread separate from the UI thread (the Run() method will block).

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.

Attach to MVC 6 process in IIS

I am hosting an asp.net 5/mvc 6 application in local IIS using dnx x64 1.0.0.rc1. I would like to attach to the iis process and debug my application, but no symbols are ever loaded for the classes that I set breakpoints in.
Is this possible with this version of dnx and IIS?
If so, how do I attach to the iis process with symbols loaded?
---UPDATE
So I've tried attaching to dnx.exe, but still no luck. Strangely, I was able to get this to work one time, but cannot replicate it again. So if anyone can outline the steps required to debug MVC 6 on IIS, please post here.
What process are you trying to attach to? I believe you should be attaching to dnx.exe