Search code examples
c#asp.net.net-4.0session-state-server

ASp.net State server dealing with IRequiresSessionState vs IReadOnlySessionState?


MY friend asked here a question

And the one who answered him - wrote something interesting ! ( without any proof , source).

It makes a bigger difference when you're using out-of-process session state storage. In that case, without the interface, the system will still store the session data in the remote database, even when it hasn't changed (the system doesn't keep track of whether the session data was modified during the request). When you use the IReadOnlySessionState interface, the write-back phase is skipped.

Where Does it say that IRequiresSessionState will write back the session ( even if hadent changed.) ?

any explanations will be gladly excepted.


Solution

  • Can't find formal documentation to this effect, but firing up dotPeek (or some other disassembler) and having a look around System.Web successively reveals that:

    • When HttpContext.Handler is set, if the handler implements IRequiresSessionState, HttpContext._requiresSessionStateFromHandler is set true;
    • this latter private member informs the getter for HttpContext.RequiresSessionState;
    • SessionStateModule (which I am gong to guess is always in the module pipeline), in its EndRequest handler, checks HttpContext.RequiresSessionState, and if it's true, talks to the session state provider to save state.