Search code examples
asp.netnhibernatesessionuser-management

ASP.net sessions, interacting with NHibernate


I have a question about how to keep the current ASP.net/User's session during the duration of a user's visit. What is the best way to keep the current User object?

Currently I am keeping it as a session object in the Session management in ASP.net. I do have Context.User.Identify.User keeping the email address/PK, but is there a better way to do this?


Solution

  • There is an overview on hibernate session and transaction management here.

    • Build a singleton session factory to take care of serving up your sessions.
    • If want to follow the session-per-request pattern, consider storing the session in Context.Items
    • Consider using the session-per-conversation:

    In this case a single Session has a bigger scope than a single database transaction and it might span several database transactions. Each request event is processed in a single database transaction, but flushing of the Session would be delayed until the end of the conversation and the last database transaction, to make the conversation atomic.