The session is a built-in object for the page class and can be used directly, but ordinary classes, such as generic processing classes, cannot be used directly.
I used a similar system.web.httpcontext.current.session["userid" in the handler class before, but the debug display
System.Web.HttpContext.Current.Session is always null.
workaround : Let the custom class implement the IRequiresSessionState interface while adding: using System.Web.SessionState;
Why do you want to implement this interface?
Here to illustrate the role of the IRequiresSessionState interface:
IRequiresSessionState: Specifies that the destination HTTP handler requires read and write access to the session-state value. This is a markup interface and there is no method.
Purpose: Implements the IRequiresSessionState interface in a custom HTTP handler to determine whether the handler needs read and write access to the session-state value.
So remember, if you want to access the session in a custom HTTP handler, be sure to implement this interface.
There is another interface, Ireadonlysessionstate, which allows only read-only operations on the session, and in addition, as with the IRequiresSessionState function.
Asp. NET custom classes use session to save information