asp.netapplication-endsessionend

Regarding Session_End and Application_End methods in asp.net


I'm trying to implement a class (lets call it CustomerConnection class) which implements System.Web.HttpApplication interface. I tried to implement two events session_end and application_end events in this class in this way:

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
    }

But it seems these events are not getting executed neither for the application end or session log out.

How should i make these events get´executed ? Is it like i have to notify to certain other event?

I'm just creating a new object of customer class. is it enough to get these events executed or my approach is fundamentally wrong?

Please help me out

Thanks in anticipation


Solution

  • You need this in global.asax:

    <%@ Application Language="C#" Inherits="CustomerConnection"%>
    

    Caveat, I've never tried this, I found it here: http://www.codedigest.com/Articles/ASPNET/34_Adding_CodeBehind_for_Gloabalasaz_x_file_in_aspnet_20.aspx