简体   繁体   English

崩溃后重新启动ASP.NET Core App

[英]Restart ASP.NET Core App after Crash

I'm new to ASP.NET Core and learning. 我是ASP.NET Core和学习的新手。 Just want to know if there is a way to restart my app after the App Crashes? 只想知道在应用程序崩溃后是否可以重新启动我的应用程序?

Or is this kind of scenario handled different? 还是这种情况处理不同?

Couldnt find any Documentation on this, can someone point me to the right direction? 找不到任何文档,有人可以指出我正确的方向吗?

If you host your ASP.NET Core application behind a full web server used as reverse proxy as IIS, it will get done automatically. 如果将ASP.NET Core应用程序托管在用作反向代理(如IIS)的完整Web服务器之后,它将自动完成。 IIS will receive a request and transmit it to your application, (re)launching it if necessary. IIS将收到一个请求并将其传输到您的应用程序,并在必要时重新启动。 You can check that great article: https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS 您可以查看该出色的文章: https : //weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS

On the contrary, if you use simply Kestrel (but it's not suitable for production really), Kestrel will stop and that's it, your app is gone. 相反,如果仅使用Kestrel(但实际上并不适合生产),则Kestrel将停止,仅此,您的应用程序就消失了。

When hosting your ASP.NET Core app as a Windows Service you can configure it to automatically restart if the service process terminates. ASP.NET Core应用程序托管为Windows Service ,可以将其配置为在服务进程终止时自动重新启动。

In your code, just do Environment.Exit(1) to terminate the process and then let the hosting environment restart it. 在您的代码中,只需执行Environment.Exit(1)即可终止该过程,然后让托管环境重新启动该过程。

How this is configured in other environments I don't know, but I guess most hosts should have this configurable in some way. 我不知道在其他环境中如何配置它,但是我想大多数主机都应该以某种方式来配置它。 IIS probably do this allready. IIS可能已经做好了准备。

However, this is only applicable to exceptions that do not allready kill your process. 但是,这仅适用于尚未完全杀死您的进程的异常。 Exceptions on a request thread don't usually crash your app but you may want to take it down and restart in anyway, perhaps if you have in-memory state that may end up in a undefined and possibly hazardous way after an exception. 请求线程上的异常通常不会使您的应用程序崩溃,但是无论如何,如果您的内存状态可能在异常发生后以不确定的方式结束,则您可能希望将其关闭并以任何方式重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM