Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 664063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:33:31+00:00 2026-05-13T23:33:31+00:00

I am using ASP MVC 2 and Nhibernate. I have created an HTTP Module

  • 0

I am using ASP MVC 2 and Nhibernate. I have created an HTTP Module as demonstrated in Summer of NHibernate 13 that looks like so:

public void Init(HttpApplication context)
{
     context.PreRequestHandlerExecute += new EventHandler(Application_BeginRequest);
     context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);
}

private void Application_BeginRequest(object sender, EventArgs e)
{

    ISession session = StaticSessionManager.OpenSession();
    session.BeginTransaction();
    CurrentSessionContext.Bind(session);
}

private void Application_EndRequest(object sender, EventArgs e)
{
  ISession session = CurrentSessionContext.Unbind(StaticSessionManager.SessionFactory);
  if (session != null)
  try
  {
      session.Transaction.Commit();
   }
   catch (Exception)
   {
       session.Transaction.Rollback();
   }
   finally
   {
       session.Flush();
       session.Close();
    }
}

web.config

<add name="UnitOfWork" type="HttpModules.UnitOfWork"/>

My problem is that Application_EndRequest never gets called on a 404 error so if my view does not render I completely block database access until my flush takes place. I am fairly new to NHibernate so I am not sure if I am missing something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:33:31+00:00Added an answer on May 13, 2026 at 11:33 pm

    You can dispose and rollback the session in application_error. change session.close into session.dispose and check if it’s not already disposed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC application using NHibernate and the application runs fine when
I'm developing an application using asp.net mvc, NHibernate and DDD. I have a service
I have been using the ncommon framework ( http://code.google.com/p/ncommon/ ) with nhibernate and asp.net
I'm currently learning ASP.NET MVC and using Nhibernate. I would like to use Cascading
I am using ASP.NET MVC 2 with nhibernate. I have this Sales class. Sales
I have a ASP.NET MVC 3 application using NHibernate over a PostgreSQL database. There
I'm using S#arpArchitecture (ASP.NET MVC and Fluent NHibernate). I have an entity as follows:
I'm using Fluent NHibernate in an Asp.net MVC application. I have it set up
I have about 4-6 years .NET experience. Primarly using ASP.NET MVC/Nhibernate/Castle Windsor/MSpec/etc in visual
I have an asp.net-mvc website and i am using ninject for IOC and nhibernate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.