Stop a Running Dotnet Core Website Running on Kestrel

Stop a running dotnet core website running on kestrel

I have decided to use supervisor to monitor and manage the process. Here is an excellent article on getting it set up.

It allows simple control over specific dotnet apps like this:

supervisorctl stop MyWebsiteName
supervisorctl start MyWebsiteName

And it has one huge advantage in that it can try restart the process if it falls over, or when the system reboots... for whatever reason.

Stop Kestrel server accepting requests from code

During the lifetime of the application I want to be able to Pause/Stop the endpoint/Server from listening/accepting requests and after a while resuming it.

This isn't possible today but will be in 5.0. I'd suggest commenting on this issue https://github.com/dotnet/aspnetcore/issues/21244

How to quit ASP.NET Kestrel web server on a Mac

It turns out that simply hitting "Enter" exits kestrel cleanly, without the need to kill the mono-sgen process afterward. There is a github issue on the Kestrel repo asking to make this more obvious.

Can I keep an ASP.NET Core web site running after stopping debugging?

Edit the properties for the web site project (right-click in Solution Explorer and select Properties) and then select the Debug tab on the right.

Under Web Server Settings, change Hosting Model to Out of Process.

Sample Image

Now, when debugging is stopped the website should continue to run in IIS Express.

Notes:

  • Tested in Visual Studio 2017 and Visual Studio 2019
  • The default hosting model for VS2017 is "In Process", in case you're wondering.
  • It does not appear to make a difference whether or not you have 'Enable Edit and Continue' selected in Tools > Options > Debugging.

How to stop a self hosted Kestrel application?

Found the most obvious way to cancel Kestrel. Run has an overload accepting a cancellation Token.

  public static class WebHostExtensions
{
/// <summary>
/// Runs a web application and block the calling thread until host shutdown.
/// </summary>
/// <param name="host">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHost" /> to run.</param>
public static void Run(this IWebHost host);
/// <summary>
/// Runs a web application and block the calling thread until token is triggered or shutdown is triggered.
/// </summary>
/// <param name="host">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHost" /> to run.</param>
/// <param name="token">The token to trigger shutdown.</param>
public static void RunAsync(this IWebHost host, CancellationToken token);
}

So passing the cancellation token to

host.Run(ct);

solves it.

How to make Kestrel console window auto close/reset upon each rebuild in Visual Studio ASP.NET Core web projects?

You mean this?

Tools → Options → Debugging → General → Automatically close the console when debugging stops



Related Topics



Leave a reply



Submit