Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ryan 34 posts 136 karma points
    Apr 14, 2015 @ 09:54
    Ryan
    0

    Extending Global.asax for Session_End

    Hi all,

    So, after searching around for a good few hours and trying various methods I'm still at a loss as to how to make this work. I'm currently developing a new web application that needs to do lots of boring stuff on 'Session_End'. It would appear that all the material I've found on this subject suggests different approaches and most of which haven't worked for me , I also recently looked at Http modules but to no avail.

    Hopefully someone can clarify the correct approach, and as always it's much appreciated. Code snippet below shows my current custom global.asax.cs, the problem is wiring up the Session_End().

    Thanks!

    public class MyGlobal : UmbracoApplication
    {
        public void Init(HttpApplication application)
        {
            application.PreRequestHandlerExecute += application_PreRequestHandlerExecute;
            application.BeginRequest += this.Application_BeginRequest;
            application.EndRequest += this.Application_EndRequest;
            application.Error += Application_Error;
    
        }
    
        protected override void OnApplicationStarted(object sender, EventArgs e)
        {
            base.OnApplicationStarted(sender, e);
    
    
        }
    
        //Not sure how to hook this into Init()
        private void Session_End(object sender, EventArgs e)
        {
            //Lots of great code
        }
    
        private void application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            try
            {
                if (Session.IsNewSession)
                {
    
                }
            }
            catch (Exception ex) { }
        }
    
        private void Application_BeginRequest(object sender, EventArgs e)
        {
    
        }
    
        private void Application_EndRequest(object sender, EventArgs e)
        {
    
        }
    
        protected new void Application_Error(object sender, EventArgs e)
        {
    
        }
      }
    }
    
  • Jeroen Breuer 4860 posts 12121 karma points MVP 3x admin c-trib
    Apr 14, 2015 @ 11:15
  • Ryan 34 posts 136 karma points
    Apr 14, 2015 @ 11:37
    Ryan
    1

    Hi Jeroen,

    I've been meaning to take a look at the Hybrid Framework for a while now, it seems to deal with a lot of the problems I seem to be encountering.

    I've just fixed my issue and it was fairly straight forward.

    1. Made sure my Session_End() method was protected and not private

      protected void Session_End(object sender, EventArgs e)
      {
         Debug.WriteLine("End");
      }
      
    2. Added a timeout value to my web.config

      <sessionState mode="InProc" timeout="2" customProvider="DefaultSessionProvider">
      

    Simple mistakes - I easily overlooked them and it cost me a fair amount of time.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft