本文介绍了如何处理来自外部的Global.asax Application_End事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以从Global.asax文件创建方法,名称Application_End附加到此事件()。但我需要连接到像这样
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?
推荐答案
已经解决了这个问题,在这样的方式。
Have solved the problem in such way.
public class MyHttpApplication:HttpApplication
{
public event Action ApplicationEnd;
protected void Application_End()
{
if (ApplicationEnd != null)
ApplicationEnd();
}
}
在Global.asax的定义
In global.asax defined
<%@ Application Inherits="MyLib.MyHttpApplication" Language="C#" %>
然后在code
Then in code
var app = HttpContext.ApplicationInstance as MyHttpApplication;
app.ApplicationEnd += () => { // do something };
这篇关于如何处理来自外部的Global.asax Application_End事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!