http://geeks.ms/blogs/gtorres/archive/2009/11/04/aspnet-mvc-nhibernate-session-per-request-y-action-filters.aspx
On Sat, Jun 26, 2010 at 12:18 PM, Felipe Oriani <[email protected]> wrote: > Hi all, I'm developing an application using Asp.Net MVC. I've developed a > session per Request... so when the browser request something from server, > the app start an session. > > By the way, I have a page in my website that each second does a > asynchronous request by Json to take some information at cache (and the > first time, the cache is loaded from database, by repositories using > Nhibernate). Everything is fine, but when I see the application running with > NHProf, I see all "ISession" per request ... but any command is executed > (because I load a cache). > > I wonder, if doing so may cause a problem in the future? Or, with many > accesses the web application may become slow ? > > At my global.asax I do this: > > public override void Init() > { > base.Init(); > > PreRequestHandlerExecute += OpenNHibernateSession; > PostRequestHandlerExecute += DisposeNHibernateSession; > } > > private static void OpenNHibernateSession(object sender, EventArgs > e) > { > if (RequestHelper.IsStaticFiles()) // || > RequestHelper.IsJson()) = to avoid calls Json if necessary, but i'll need > use h in some called jsons > return; > > ManagedWebSessionContext.Bind(HttpContext.Current, > _sessionFactory.OpenSession()); > } > > private static void DisposeNHibernateSession(object sender, > EventArgs e) > { > if (RequestHelper.IsStaticFiles()) // || > RequestHelper.IsJson()) > return; > > var session = > ManagedWebSessionContext.Unbind(HttpContext.Current, _sessionFactory); > if (session != null) > session.Dispose(); > > } > > If someone can help-me... I'll! appreciate > > PS: Sorry for my english! > > Cheers > > > > > -- > ______________________________________ > Felipe B. Oriani > [email protected] | www.felipeoriani.com.br > > "...Trabalhe quanto puder, tornando-se útil quanto possível..." , por André > Luiz > > -- > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- Fabio Maulo -- 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.
