我试图找出热门来重启MVC6应用程序。我有这个代码片段可以阻止它,但它出错了。
private readonly IApplicationShutdown applicationShutdown;
public AdminController(IApplicationShutdown applicationShutdown)
{
this.applicationShutdown = applicationShutdown;
}
public IActionResult RestartApplication()
{
this.applicationShutdown.RequestShutdown();
}
这里给出了这个错误。
InvalidOperationException:无法解析类型' Microsoft.Extensions.PlatformAbstractions.IApplicationShutdown' ...
答案 0 :(得分:3)
新的IApplicationShutdown
接口取代了过时的IApplicationLifetime
接口(请参阅:Proof link)。
使用IApplicationLifetime.StopApplication()
方法终止应用程序。
private readonly IApplicationLifetime applicationLifetime;
public AdminController(IApplicationLifetime applicationLifetime)
{
this.applicationLifetime = applicationLifetime;
}
public IActionResult RestartApplication()
{
this.applicationLifetime.StopApplication();
}
但请记住,在终止应用程序后,您必须再次启动应用程序。