Nhibernate session created on every web request in asp.net MVC2

I have an ASP.net MVC2 application using NHibernate to access data. With each request, even static requests for files (images, javascript) creates a new session. Therefore, for one view, where I return the list, I create about 15 sessions that do not load anything.

Is there a way to create sessions only when they are required?

I am currently using Castle.Windsor to enter a session into my controllers.

Is there a way to filter out static file requests?

+3
source share
4 answers

, NHibernate MVC. , ASP.net ASP.net. IIS ASP.net, .

(http://www.asp.net/hosting/tutorials/core-differences-between-iis-and-the-asp-net-development-server-cs)

IIS ASP.NET Development Server - . , ASP.NET, ASP.NET, , JavaScript, ASP.NET. IIS ASP.NET, ASP.NET , - ASP.NET, - .. - , CSS , JavaScript, PDF, ZIP .. - IIS ASP.NET.

+3

, :

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // add these lines
    routes.IgnoreRoute("{resource}.jpg");
    routes.IgnoreRoute("{resource}.js");
}

, , . , .

+3

, .jpg ISession, ( ), factory?

,

  • , factory
  • PerWebRequest, OpenSession SessionFactory

    //Setup the Hibernate dependencies
        container.AddFacility<FactorySupportFacility>().Register(
            Component.For<ISessionFactory>().LifeStyle.Singleton
                .Instance(NHibernateHelper.GetSessionFactory()),
            Component.For<ISession>().LifeStyle.PerWebRequest
                .UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession())
            );
    

    , MVC factory, PerWebRequest .

,

+1

Spring.NET, Castle Windsor, , . ISession , , , dbones. MVC , .jpg , ISession.

Castle Windsor ? . , Global.asax, Windsor ISession?

0

Source: https://habr.com/ru/post/1774173/


All Articles