Archive

Archive for December 26, 2008

How to manipulate Session in Http Handlers

December 26, 2008 Imran Akram Leave a comment

There is a common issue that you can’t manipulate session objects in http handlers, the files with ASHX extension :) Well normally you can read the contents in the session via context.Session but you can add/remove/modify that in there. So how do you do this:

The answer is simple: Just implement the IRequiresSessionState interface. It doesnt have any method to implement so you dont have to worry about any details, this just notifies the runtime that Session can be manipulated in this context. So your class declaration would look something like this:-

public class SetLabels : IHttpHandler, IRequiresSessionState
{