Wednesday, April 21, 2010

ASP .Net Generic Handlers and Session

For session state to be available to a handler, the handler has to implement IReadOnlySessionState (for read-only access) or IRequiresSessionState (for read-write access). For example:

public class MyHandler : IHttpHandler, IRequiresSessionState
{
// ...
}

There are no actual methods to implement for IRequiresSessionState - it is just a "marker" interface that ASP.NET will look for at runtime. If it find the interface it goes to the trouble of making session state available.