HttpHandler with Session State
20/01/2010 Leave a comment
If you are developing httphandler in asp.net realized that httphandlers can not use session as default.If you want to access session object do it as below.
Add “System.Web.SessionState” namespace to your handler code.
There are two interface . one of them must be inherited by your httphandler object:
IRequiresSessionState Interface
Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.
Specifies that the target HTTP handler requires only read access to session-state values. This is a marker interface and has no methods.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace PostmanExamples
{
// IRequireSessionState if you want write access
public class MyHttpHandlerWithSessionState
: IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
string s = context.Session["SomeSessionVariable"];
}
public bools IsReusable { get { return true; } }
}
}