i try. This work fine for me (the nhibernate part)

On Sep 13, 5:20 pm, Fabio Maulo <[email protected]> wrote:
> Take care with that implementation...Try it opening two in
> depended conversations in two tabs (instead two browser instances).
>
> 2009/9/13 danyelleon <[email protected]>
>
>
>
>
>
>
>
> > Hi !
>
> > I use a custom httpmodule for implement an nhibernate session per
> > conversation pattern in my asp.net web proyect. This work fine. I
> > recently wants add ajax support for the site, but i recive this error
> > in the browser:
>
> > Message: ASP.NET Ajax client-side framework failed to load.
> > Line: 40
> > Char: 34
> > Code: 0
> > URI:http://localhost/thpcu/prueba.aspx
>
> > Message: 'Sys' is undefined
> > Line: 52
> > Char: 1
> > Code: 0
> > URI:http://localhost/thpcu/prueba.aspx
>
> > Message: 'Sys' is undefined
> > Line: 70
> > Char: 1
> > Code: 0
> > URI:http://localhost/thpcu/prueba.aspx
>
> > the section in web.config for the modules are here:
>
> >    <httpModules>
> >      <add name="NHibernateSessionPerConversationModule"
> > type="Thpcu.Tapi.Web.NHibernateSessionPerConversationModule,
> > Thpcu.Tapi.Web"/>
> >      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
> > System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
> > PublicKeyToken=31BF3856AD364E35"/>
> >    </httpModules>
>
> > If i coment my custom module, ajax work fine. But whit the module
> > active, the error apear. I search in internet but almost all answer
> > for this error are for a bad configured web.config file. In my case, i
> > use visual studio 2008 that create a full configured web.config for
> > support ajax, and i use the 3.5 sp1 framework, that have full suport
> > for ajax too.
>
> > Why this simple custom module cause the ajax error?
>
> > Some help please !
>
> > Thanks in advance.
>
> > The code for http module:
>
> > using System;
> > using System.Data;
> > using System.Configuration;
> > using System.Linq;
> > using System.Web;
> > using System.Web.Security;
> > using System.Web.UI;
> > using System.Web.UI.HtmlControls;
> > using System.Web.UI.WebControls;
> > using System.Web.UI.WebControls.WebParts;
> > using System.Xml.Linq;
> > using NHibernate.Context;
> > using Thpcu.Tapi.Infraestructure;
> > using NHibernate;
>
> > namespace Thpcu.Tapi.Web
> > {
> >    public class NHibernateSessionPerConversationModule : IHttpModule
> >    {
> >        #region Constants
>
> >        private const string NHIBERNATE_CONVERSATION_END_FLAG_KEY =
> > "hibernate.conversation.end.flag";
>
> >        private const string NHIBERNATE_CURRENT_SESSION_KEY =
> > "hibernate.session";
>
> >        #endregion
>
> >        #region Public Methods
>
> >        public void Dispose()
> >        {
> >        }
>
> >        public static void EndConversationAtTheEndOfThisRequest()
> >        {
> >            HttpContext.Current.Items
> > [NHIBERNATE_CONVERSATION_END_FLAG_KEY] = true;
> >        }
>
> >        public void Init(HttpApplication context)
> >        {
> >            context.PreRequestHandlerExecute += new EventHandler
> > (Application_PreRequestHandlerExecute);
> >            context.PostRequestHandlerExecute += new EventHandler
> > (Application_PostRequestHandlerExecute);
> >        }
>
> >        #endregion
>
> >        #region Private Methods
>
> >        private void Application_PreRequestHandlerExecute(object
> > sender, EventArgs e)
> >        {
> >            PerformRequest(true);
> >        }
>
> >        private void Application_PostRequestHandlerExecute(object
> > sender, EventArgs e)
> >        {
> >            PerformRequest(false);
> >        }
>
> >        private void PerformRequest(bool begin)
> >        {
> >            try
> >            {
> >                if (begin)
> >                    Application_BeginRequest();
> >                else
> >                    Application_EndRequest();
> >            }
> >            catch (StaleObjectStateException staleEx)
> >            {
> >                // This implementation does not implement optimistic
> > concurrency control!
> >                // Your application will not work until you add
> > compensation actions!
> >                // Rollback, close everything, possibly compensate for
> > any permanent changes
> >                // during the conversation, and finally restart
> > business conversation. Maybe
> >                // give the user of the application a chance to merge
> > some of his work with
> >                // fresh data... what you do here depends on your
> > applications design.
> >                throw staleEx;
> >            }
> >            catch (Exception ex)
> >            {
> >                // Rollback only
> >                try
> >                {
> >                    if (CurrentSessionContext.HasBind
> > (StaticSessionManager.SessionFactory))
> >                        StaticSessionManager.GetCurrentSession
> > ().Transaction.Rollback();
> >                }
> >                catch
> >                {
> >                    // Could not rollback transaction after exception!
> >                }
> >                finally
> >                {
> >                    // Close the conversation and cleanup
> >                    HttpContext.Current.Session
> > [NHIBERNATE_CURRENT_SESSION_KEY] = null;
> >                    ISession currentSession =
> > CurrentSessionContext.Unbind(StaticSessionManager.SessionFactory);
> >                    if (currentSession != null)
> >                        currentSession.Close();
> >                }
> >                // Let others handle it...
> >                //throw new InfrastructureException(ex);
> >            }
> >        }
>
> >        private void Application_BeginRequest()
> >        {
> >            // Continuing a conversation?
> >            ISession currentSession = (ISession)
> > HttpContext.Current.Session[NHIBERNATE_CURRENT_SESSION_KEY];
> >            if (currentSession == null)
> >            {
> >                // New conversation
> >                currentSession = StaticSessionManager.OpenSession();
> >                currentSession.FlushMode = FlushMode.Never;
> >            }
> >            CurrentSessionContext.Bind(currentSession);
> >            currentSession.BeginTransaction();
> >        }
>
> >        private void Application_EndRequest()
> >        {
> >            // Unbinding Session after processing
> >            ISession currentSession = CurrentSessionContext.Unbind
> > (StaticSessionManager.SessionFactory);
>
> >            // End or continue the long-running conversation?
> >            if (HttpContext.Current.Items
> > [NHIBERNATE_CONVERSATION_END_FLAG_KEY] != null)
> >            {
> >                currentSession.Flush();
> >                currentSession.Transaction.Commit();
> >                currentSession.Close();
> >                HttpContext.Current.Session
> > [NHIBERNATE_CURRENT_SESSION_KEY] = null;
> >                HttpContext.Current.Response.Redirect
> > (HttpContext.Current.Request.CurrentExecutionFilePath);
>
> >            }
> >            else
> >            {
> >                currentSession.Transaction.Commit();
> >                HttpContext.Current.Session
> > [NHIBERNATE_CURRENT_SESSION_KEY] = currentSession;
> >            }
> >        }
>
> >        #endregion
> >    }
> > }
>
> --
> Fabio Maulo- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to