【问题标题】:It it possible to catch and handle website unload event - asp.net web pages razor 2?是否可以捕获和处理网站卸载事件 - asp.net web pages razor 2?
【发布时间】:2013-11-12 15:55:49
【问题描述】:

是否可以检测到 Razor 2 网页应用程序 (asp.net) 何时被卸载 - 例如,由于 IIS/WebMatrix 被停止?

有_AppStart.csthml 来处理应用程序的启动。

“应用程序停止”有类似的东西吗?

编辑:

声誉低,我自己还不能投票/回答。

我添加了 Global.asax,确实有用于处理应用关闭的 Application_End 事件。

我可以改用它吗,还是首选您的方法?

void Application_End(object sender, EventArgs e) 
{
    //  Code that runs on application shutdown

}

【问题讨论】:

    标签: c# asp.net .net razor


    【解决方案1】:

    您可以通过在运行 aspx.net 应用程序的域上使用“DomainUnload”事件处理程序来解决此问题。

    例如;

    void Application_Start(object sender, EventArgs e)
    {
        ...
        AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
    }
    
    void CurrentDomain_DomainUnload(object sender, EventArgs e)
    {
        // Cleanup code here
    }
    

    希望这会有所帮助,

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 2020-04-11
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多