开发者

Nhibernate with Asp.net WebForms - Session per Request

I am using an HttpModule to open a session that span each request and it works great with lazy loading and everything.

My concern is that since I open a new session per request (and stores it in HttpContext.Current.Items) it opens a session for every request even request including request f开发者_JAVA百科or .css files and images. I recall reading that session creation is a pretty lightwheigt operation (dont know about transactions though) but anyway it seems unnecessary to open a session for a requests for a .css file?

Anyone got some ideas about this, is it a problem and/or am I doing something stupid?

Thanks in advance


  • only create the session object if the file type is .aspx or .ashx:

        switch (context.Request.CurrentExecutionFilePathExtension.ToLower())
        {
            case ".aspx":
            case ".ashx":
                context.Items[ContextKey] = CreateMySession();
                break;
        }
    
  • or encapsulate session creation inside a property getter, and clean-up checks whether session != null

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜