Developer forum

Forum » Development » "Subcribe" to SessionStart/End in DW7

"Subcribe" to SessionStart/End in DW7

Nuno Aguiar
Reply
Hi,

We have a project we cannot upgrade right now, that uses some custom methods in Session start/end and Application_PreRequestHandlerExecute

Is there a way to NOT change the global.asax, meaning, using the standard default global.asax that comes with Dynamicweb?

Nuno


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
 Hi Nuno,

What about writing your own implementation in a separate class library, deploy it to the bin folder of the app and just change the inherits attribute of the Global.asax file? That way you can inject your own code without really changing the solution.

What's the reason you can't / don't want to change the Dynamicweb Global.asax file?

Cheers,

Imar
 
Nuno Aguiar
Reply
Hi Imar,

It's for our biggest client in Portugal. He has internal hosting and development and develops a lot of small modules. They have an internal rule not to change the default.aspx and global.asax files, so programmers don't develop conflicted code and harm performance.

I really need to run some methods on Session_Start and Session_End, but without changing Global.asax. Changing the inherits attibute is the change they don't accept.

Any other thoughts?

Nuno

 
Nicolai Høeg Pedersen
Reply
To the best of my knowledge there are no ways to listen to those application events without going through Global.asax.
See docs: http://msdn.microsoft.com/en-us/library/fwzzh56s.aspx

As an alternative you can do something with the Notifications.Standard.Application.BeginRequest notification. But that would be keeping track on if sessions are started already etc. Not a good solution compared to changing the global.asax file.

Also, DW does not add things to Global.asax - everything is forwarded to the GlobalAsaxHandler, i.e. GlobalAsaxHandler.Application_OnPreRequestHandlerExecute(sender, e).

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
Yes, that was my assumption also: you need Global.asax for application-wide events. You may be able to handle
PreRequestHandlerExecute using an HttpModule running into integrated mode, but that may not be enough for your requirements....

Imar
 
Morten Bengtson
Reply
You could create a separate http module, like this...
public class CustomSessionHandlerModule : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
            // clean-up code here.
        }

        public void Init(HttpApplication context)
        {
            var sessionModule = context.Modules["Session"] as System.Web.SessionState.SessionStateModule;
            if (sessionModule != null)
            {         
                sessionModule.Start += OnSessionStart;
                sessionModule.End += OnSessionEnd;
            }
        }        

        #endregion

        public void OnSessionStart(object source, EventArgs e)
        {
            // Add custom code for session start here
        }

        private void OnSessionEnd(object sender, EventArgs e)
        {
            // Add custom code for session end here
        }
    }


However, you will need to register it in web.config...
<system.web>
    <httpModules>
        <add name="CustomSessionHandlerModule" type="CustomModules.CustomSessionHandlerModule" />
    </httpModules>
</system.web>




 
Nuno Aguiar
Reply
Hi Nicolai and Imar,

Thanks for the input. Effectivelly we will need to develop a schedule task to overcome the Session_End problem.

The thing is, we need to clean our database on Session_End, but the website we are developing only represents a percentage of the http request of that solution (hosts more than 1 website). It's actually a dead end if we need to maintain a single solution for multiple websites, and manage session_end on a single website.

Thank you both.

Nuno

 
Nuno Aguiar
Reply
Hi Morten,

That's a great solution, we will try that along with the schedule task and see what end's up fitting best with this client's server structure (it's pretty tricky).

Best Regards,
Nuno

 

You must be logged in to post in the forum