2011-04-16 75 views
0

我试图实现一个类(让我们称之为CustomerConnection类)实现System.Web.HttpApplication接口。我试图实现两个事件Session_End中,以这种方式application_end事件在这个类:关于Session_End和Application_End方法在asp.net

public class CustomerConnection: System.Web.HttpApplication 
{ 


    protected void Session_End(object sender, EventArgs e) 
    { 
     HttpApplication application = (HttpApplication)sender; 
     HttpContext context = application.Context; 
     SqlConnection connection = context.Items[Database_Con] as SqlConnection; 
     connection.close(); 

    } 

    protected void Application_End(object sender, EventArgs e) 
    { 
     HttpApplication application = (HttpApplication)sender; 
     HttpContext context = application.Context; 
     //someotherEvent 
    } 

但似乎这些事件都没有得到既不结束应用程序或会话日志进行执行。

我应该如何让这些事件得到执行?这是否像我必须通知某些其他事件?

我刚刚创建了一个客户类的新对象。是否足以让这些事件得到执行或者我的方法根本错误?

请帮我

感谢预期

回答

0

您创建的没有连接到任何对象,所以不能接收来自应用程序的任何事件。您必须将事件处理程序放入用于Web应用程序的对象中,即Global.asax.cs文件中。

此外,没有Session_End事件,它是Session_OnEnd