HttpModule method of using scope in an ASP.NET page - timeouts...

5 posts, 0 answers
  1. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 18 Aug 2010 Link to this post

    Hi

    I am using the HttpModule method of creating a scope object in my ASP.NET web application. This is described here.

    Please can you tell me how to prevent my page from timing out.

    I have set session timeout for about 3 hours and yet the Telerik ORM connection seems to timeout after about 5 minutes.

    Kind Regards

    David
  2. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 18 Aug 2010 Link to this post

    Below is my ScopeModule...

    using System;
    using System.Web;
     
    namespace Heron.App_Code
    {
        /// <summary>
        ///
        /// </summary>
        public class ScopeModule : System.Web.IHttpModule
        {
            /// <summary>
            /// Inits the specified lo context.
            /// </summary>
            /// <param name="loContext">The lo context.</param>
            public void Init(HttpApplication loContext)
            {
                loContext.PreRequestHandlerExecute += new EventHandler(Context_PreRequestHandlerExecute);
                loContext.PostRequestHandlerExecute += new EventHandler(Context_PostRequestHandlerExecute);
            }
     
            /// <summary>
            /// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule"/>.
            /// </summary>
            public void Dispose()
            {
            }
     
            /// <summary>
            /// Handles the PostRequestHandlerExecute event of the Context control.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
            private void Context_PostRequestHandlerExecute(object sender, EventArgs e)
            {
                try
                {
                    if (HttpContext.Current.Session != null)
                    {
                        this.CommitTransaction();
                        this.DisposeScope();
                        this.ClearSession();
                    }
                }
                catch (Exception loException)
                {
                    Heron.App_Code.L.Exception("ScopeModule: Error! Context_PostRequestHandlerExecute.", loException);
                }
            }
     
            /// <summary>
            /// Handles the PreRequestHandlerExecute event of the Context control.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
            private void Context_PreRequestHandlerExecute(object sender, EventArgs e)
            {
                try
                {
                    if (HttpContext.Current.Session != null)
                    {
                        HttpContext.Current.Session["Heron_oScope"] = Heron.PersistentClasses.ObjectScopeProvider.ObjectScope();
                        HttpContext.Current.Session["Heron_oChangeTracker"] = new Heron.PersistentClasses.DB.ChangeTracker((Telerik.OpenAccess.IObjectScope)HttpContext.Current.Session["Heron_oScope"], (Heron.PersistentClasses.SV.LoginState.IsLoggedIn) ? Heron.PersistentClasses.SV.LoginState.ProfileHeron.nBillingCompany_ENT_nID : -1, Heron.PersistentClasses.SV.LoginState.Application, (Heron.PersistentClasses.SV.LoginState.IsLoggedIn) ? (Guid?)Heron.PersistentClasses.SV.LoginState.User.ProviderUserKey : null, Heron.Library.Library.GetSMTPHost());
                        ((Heron.PersistentClasses.DB.ChangeTracker)HttpContext.Current.Session["Heron_oChangeTracker"]).Start();
                        this.CreateTransaction();
                    }
                }
                catch (Exception loException)
                {
                    Heron.App_Code.L.Exception("ScopeModule: Error! Context_PreRequestHandlerExecute.", loException);
                }
            }
     
            /// <summary>
            /// Creates the transaction.
            /// </summary>
            protected void CreateTransaction()
            {
                ((Telerik.OpenAccess.IObjectScope)HttpContext.Current.Session["Heron_oScope"]).Transaction.Begin();
            }
     
            /// <summary>
            /// Commits the transaction.
            /// </summary>
            protected void CommitTransaction()
            {
                if (((Telerik.OpenAccess.IObjectScope)HttpContext.Current.Session["Heron_oScope"]).Transaction.IsActive)
                {
                    ((Telerik.OpenAccess.IObjectScope)HttpContext.Current.Session["Heron_oScope"]).Transaction.Commit();
                }
            }
     
            /// <summary>
            /// Disposes the scope.
            /// </summary>
            protected void DisposeScope()
            {
                ((Heron.PersistentClasses.DB.ChangeTracker)HttpContext.Current.Session["Heron_oChangeTracker"]).Stop();
                HttpContext.Current.Session["Heron_oChangeTracker"] = null;
                ((Telerik.OpenAccess.IObjectScope)HttpContext.Current.Session["Heron_oScope"]).Dispose();
                HttpContext.Current.Session["Heron_oScope"] = null;
            }
     
            /// <summary>
            /// Clears the session.
            /// </summary>
            protected void ClearSession()
            {
                HttpContext.Current.Session.Remove("Heron_oChangeTracker");
                HttpContext.Current.Session.Remove("Heron_oScope");
            }
        }
    }
  3. DevCraft banner
  4. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 19 Aug 2010 Link to this post

    Hi David,

    I don't think your timeout has something to do with the session timeout value. I think it has something to do with your session timeout value being different from the timeout of the underlying database connection / connection pool.

    However, do you need to store the scope in the session?
    There's another (likely) implementation that uses HttpContext.Current.Items instead. This is based on the one request (thread) - one scope approach, where the scope lives and dies with the request and you can gain access to the scope from anywhere in your webapp.

    Also, are there any chances that you have a scope that under some circumstances does not get removed from the session and Disposed properly.

    Regards

    Henrik

  5. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 19 Aug 2010 Link to this post

    Hi

    Thanks for the reply.

    Do you have an example?

    Kind Regards

    David
  6. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 19 Aug 2010 Link to this post

    Hi David,

    See this example.

    I know it is not exactly what you are doing know. But the idea of how to store the retrieved object scope with the current request/thread in the HttpContext.Current.Items collection is the same.

    Regards

    Henrik

Back to Top
DevCraft banner