C# Using sessions in a generic handler

Generic handlers can be very useful.
Default when creating a new handler it will not support the session variable.

 

To  access the session variable you must specify that the handle requires access to the session variable.
Include one of the following interfaces: IRequiresSessionState or IReadOnlySessionState.
Be careful when using the IReadOnlySessionState because you will not be able to edit the session, attempting to do so will not raise an error and may cause you to overlook the error in your code.

 

Sample code

    public class FriendsRequest : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //Your code here
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

For more information see http://msdn.microsoft.com/en-us/library/system.web.sessionstate.aspx