如何重新启动asp.net core发布的应用程序

发布于 2025-01-21 03:41:31 字数 209 浏览 2 评论 0 原文

在主机上发布的ASP.NET核心应用程序上更改AppSettings.json时,我有一个问题,我想更改设置并重新启动应用程序以使用新设置。但是我不知道如何重新启动该应用程序。

在ASP.NET WebForms中,我们更改Web.config及其迫使应用程序重新启动。但是在ASP.NET核心中,这是行不通的。

AppSettings.json更改时如何重新启动应用程序?

I have a problem with changing appsettings.json on the asp.net core application that is published on the host, I want to change the settings and restart the app to use new settings. but I don't know how to restart the app.

in ASP.NET webforms, we change the web.config, and its forces the application to restart. but in asp.net core, it's not work.

how to restart the application when appsettings.json changes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素年丶 2025-01-28 03:41:31
  • can 仍然使用 web.config in IIS at asp.net core ...
    • 即使ASP.NET Core不再使用 Web.config 文件,IIS仍然使用 web.config 设置IIS Web-Server设置(in < system.webserver> )。
    • 因此,甚至添加了一个stub web.config 文件,然后对其进行一些微不足道的更改(我认为 touch web.config 虽然不会起作用)然后IIS将重新启动该网站的应用程序基于该虚拟 - dir或应用程序 - 范围。
  • You can still use web.config in IIS with ASP.NET Core... sort-of:
    • Even though ASP.NET Core doesn't use web.config files anymore, IIS still uses web.config to set IIS web-server settings (in <system.webServer>).
    • So adding even a stub web.config file, then making some insignificant change to it (I don't think touch web.config will work, though) then IIS will restart the website's application based in that virtual-dir or application-scope.
征﹌骨岁月お 2025-01-28 03:41:31

您可以停止应用程序,然后手动重新加载页面将再次运行该应用程序。

public class StopApp
{
    private readonly IHostApplicationLifetime _host;
    public StopApp(IHostApplicationLifetime host)
    {
        _host = host;
    }

    public class Stop()
    {
        _host.StopApplication();
    }
}

You can stop the app, and then reloading the page manually will run the app again.

public class StopApp
{
    private readonly IHostApplicationLifetime _host;
    public StopApp(IHostApplicationLifetime host)
    {
        _host = host;
    }

    public class Stop()
    {
        _host.StopApplication();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文