0

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

2
  • you mean HttpModule, not HttpHandler, right? Commented May 6, 2011 at 11:10
  • You are right ofcourse, the answer is edited now. Thanks Commented May 9, 2011 at 12:28

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

How expensive is it to begin an Nhib Transaction for every request (per aspx/ashx)? Can I have a transaction for every request or should I open them explicitly when needed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.