Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
How to Access SessionState in a custom HttpHandler

I create a lot of custom HttpHandlers to performa all sorts of tasks. I like them because you get complete control over the content produced by the server to satisfy the request. Occasionally I need to interact with the user's session. The other day I was working on a custm handler and needed to read a value in the session and I found I could not. I was just lost, then I remembered the HttpHander needed to implement the IRequiresSessionState interface.

 

public abstract class BaseHttpHandler : IHttpHandler, IRequireSessionState
{
 ...
}

 

Here is the interesting thing about the IRequiresSessionState interface, it is an empty interface. It has no members that actually need to be implemented. Somewhere under the innerworkings of the ASP.NET engine this triggers access to the Session state provider.

Posted: Thursday, September 17, 2009 9:03 AM

by Chris Love

Comments

Yasser said:

Hi Chris, I have tried this but it only works in IE and not in Firefox! Any ideas? Thanks
# January 25, 2010 12:45 PM

Chris Love said:

I would have no clue why, session is maintained on the server. Maybe you have cookies disabled in FireFox? The session id token is maintained in a cookie on the client.

# February 2, 2010 12:58 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS