This is a migrated thread and some comments may be shown as answers.

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

4 Answers 103 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
hkdave95
Top achievements
Rank 2
hkdave95 asked on 18 Aug 2010, 05:13 PM
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

4 Answers, 1 is accepted

Sort by
0
hkdave95
Top achievements
Rank 2
answered on 18 Aug 2010, 05:29 PM
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");
        }
    }
}
0
IT-Als
Top achievements
Rank 1
answered on 19 Aug 2010, 12:04 PM
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

0
hkdave95
Top achievements
Rank 2
answered on 19 Aug 2010, 03:51 PM
Hi

Thanks for the reply.

Do you have an example?

Kind Regards

David
0
IT-Als
Top achievements
Rank 1
answered on 19 Aug 2010, 04:15 PM
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

Tags
General Discussions
Asked by
hkdave95
Top achievements
Rank 2
Answers by
hkdave95
Top achievements
Rank 2
IT-Als
Top achievements
Rank 1
Share this question
or