2

Is it possible to detect when a Razor 2 Web Pages application (asp.net) is being unloaded - for example, as a result of IIS/WebMatrix being stopped?

There is _AppStart.csthml to handle the application start.

Is there something similar for "application stop"?

EDIT:

Low reputation, cannot vote up/answer myself yet.

I have added Global.asax and indeed there is Application_End event for handling app shutdown.

Can I use that instead, or your method is preferred?

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

}
4

1 回答 1

2

您可以通过在运行 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
}

希望这可以帮助,

于 2013-11-12T16:14:34.600 回答