重启asp.net MVC 6应用程序

时间:2015-12-12 10:23:30

标签: asp.net-core-mvc

我试图找出热门来重启MVC6应用程序。我有这个代码片段可以阻止它,但它出错了。

private readonly IApplicationShutdown applicationShutdown;
public AdminController(IApplicationShutdown applicationShutdown)
{
    this.applicationShutdown = applicationShutdown;
}

public IActionResult RestartApplication()
{
    this.applicationShutdown.RequestShutdown();
}

这里给出了这个错误。

  

InvalidOperationException:无法解析类型' Microsoft.Extensions.PlatformAbstractions.IApplicationShutdown' ...

1 个答案:

答案 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();
}

但请记住,在终止应用程序后,您必须再次启动应用程序。