如何处理来自 global.asax 外部的 Application_End 事件
我们可以通过名为 Application_End() 的 global.asax 文件创建方法附加到此事件。但我需要像这样附加
HttpContext.ApplicationInstance.ApplicationEnd+=OnApplicationEnd;
它有什么办法吗?
We can attach to this event from global.asax file creating method with name Application_End(). But I need to attach to it like this
HttpContext.ApplicationInstance.ApplicationEnd+=OnApplicationEnd;
Is there any way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就这样解决了问题。
在 global.asax 中定义
然后在代码中
Have solved the problem in such way.
In global.asax defined
Then in code
Application_End 是一个特殊的“事件”,由 Asp.net 调用,不属于 HttpApplication 类。
来自MSDN
*Application_Start 和 Application_End 方法是不代表 HttpApplication 事件的特殊方法。 ASP.NET 在应用程序域的生命周期内调用它们一次,而不是针对每个 HttpApplication 实例。*
我认为您可以将相同的行为附加到 AppDomain.DomainUnload 事件并处理程序
Application_End is a special "event" that is called by Asp.net that doesn't belog to the HttpApplication class.
From MSDN
*The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.*
I think you can have the same behaviour attaching and handler to the AppDomain.DomainUnload event
我知道答案已经给出,但也想包括这样的方式:
I know the answer is already given but wanted to also include this way: