Copied to clipboard

Flag this post as spam?

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


  • Roger Sutton 52 posts 124 karma points
    Jun 27, 2011 @ 11:22
    Roger Sutton
    1

    Accessing the Session_Start function

    Hi,

    I have a requirement to set up a number of session variables at the start of each session but cannot find a way to access the Session_Start function. There seems to be a lot of conflicting advice depending on the version being used. We are currently 4.6.2 and soon will be 4.7.1 and we have tried to inherit from Umbraco:Global but with no success.

    I'm obviously missing something or cannot see the right thread. Can anybody point me in the right direction?

    Thanks

    Roger

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jun 27, 2011 @ 13:11
    Lee Kelleher
    0

    Hi Roger,

    Quick check, have you deleted the "App_global.asax.dll" from the /bin directory? As that would be taking presidence.

    For further reading, Matt Brailsford has a blog post about it: Registering an Application_Start Event Handler in Umbraco

    Cheers, Lee

  • Roger Sutton 52 posts 124 karma points
    Jun 27, 2011 @ 14:09
    Roger Sutton
    1

    Hi Lee,

    Amazing how explaining stuff to someone else helps you get a better handle on what you are doing.

    To gain access to Session_Start in versions over 4.5 (maybe lower as well) simply delete the app_Global.asax.dll from the Bin folder. Add a global.asax to the project root, delete all the handlers except Session_Start and add inherits="umbraco.Global" to the header line, eg.

    <%@ Application Language="C#" Inherits="umbraco.Global"%>
    
    <script runat="server">
        void Session_Start(object sender, EventArgs e) 
        {
            // Code that runs when a new session is started
            Session["test"] = "hello";
        }
    </script> 

    This works fine and allows us to set up and initialise session variables. I don't know what umbraco.Global does in the other handlers so I have deleted them from my version as it is only Session_Start I want access to and umbraco.Global doesn't use it.

    It may be you can cover them by calling the base handlers first, eg.

    <%@ Application Language="C#" Inherits="umbraco.Global"%>
    
    <script runat="server">
    
        void Application_Start(object sender, EventArgs e) 
        {
            // Call Global base class first
            base.Application_Start(sender, e);
    
            // Bespoke code that runs when the application is started
            Application["test"] = "hello";
        }
    
    void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started Session["test"] = "hello"; } </script>
     

    I haven't tried this but it should work I think. I hope this is useful to others who have found quite a lot of conflicting material running across several versions.

    Regards

    Roger

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies