The Visual Studio development webserver will first a session for every web request whether it's something in your controller or a static file request (images, css, js,...)

IIS is smarter in that it won't send static file requests though ASP.net

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

I asked this on SO a while ago.

http://stackoverflow.com/questions/4148757/nhibernate-session-created-on-every-web-request-in-asp-net-mvc2/4149869#4149869




On Mar 31, 2011 2:52pm, rhartzog <[email protected]> wrote:
I am set up for session per web request, and every single tiny thing

gets a session. Did I set something up wrong or is this normal? In

nhprof I can see 8 session created for a home page which doesn't even

call for a session. Things like /Scripts/jquery.js, /Content/

image1.jpg, favicon.ico all get a session.



In global.asax:

public static ISessionFactory SessionFactory =

CreateSessionFactory();

public MvcApplication()

{

BeginRequest += MvcApplication_BeginRequest;

EndRequest += MvcApplication_EndRequest;

}



void MvcApplication_BeginRequest(object sender, EventArgs e)

{

if (HttpContext.Current.Items["CurrentSession"] == null)

{

HttpContext.Current.Items["CurrentSession"] =

SessionFactory.OpenSession();

}

}



void MvcApplication_EndRequest(object sender, EventArgs e)

{

var session =

(ISession)HttpContext.Current.Items["CurrentSession"];



if (session != null)

{

session.Dispose();

}

}



IoC container returns session as it's needed:



kernel.Bind().ToConstant((ISession)HttpContext.Current.Items["CurrentSession"]);



I put a screenshot of nhprof screen up showing all of the spawned

sessions, you can see it here ( NhSetup?authkey=Gv1sRgCJ23-Pqi_djZlwE#5590318316646382866" target="_blank">https://picasaweb.google.com/rhartzog/

NhSetup?authkey=Gv1sRgCJ23-Pqi_djZlwE#5590318316646382866). Any help

would be appreciated.



--

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.




--
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