asp.netnhibernatesessionglobal-asaxasp.net-session

Global asax and application_endrequest asp.net


When I run my method in global.asax it doesn't run and when I use IHttp module it is working. Please give any advice. Maybe it is caused of :

 context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);

Is it possible to call it without Module?

Code Example:

Method that I run:

    public static void EndSession()
    {
        HttpContext context = HttpContext.Current;
        if (context.Session != null)
        {
            ISession session = context.Session["Session"] as ISession;
            if (context.Session["Session"] != null)
            {
                if (!session.Transaction.IsActive)
                    OpenTransaction(session);
                session.Flush();
                CommitTransaction(session);
                session.Close();
                context.Session["Session"] = null;
            }
        }
    }

Global:

    private void Application_EndRequest(object sender, EventArgs e)
    {
       NhSessionHelper.EndSession();
    }

IHTTPMODULE:

namespace MME.DAL.SesionManager
       {
    internal class SessionRequest : IHttpModule
    {
        #region Public Methods

        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);
        }

        #endregion

        #region Private Methods

        private void Application_EndRequest(object sender, EventArgs e)
        {
           NhSessionHelper.EndSession();
        }

        #endregion
    }
}

Solution

  • Ok I understand now PostRequestHandlerExecute fires page finishes execution so the name of

    private void Application_EndRequest(object sender, EventArgs e)

    was little confusing and that is why there was a problem.