Creating a custom HttpHandler is fairly simple, all you need to do is implement the IHttpHandler interface.

public class MyHttpHandler : IHttpHandler

I recently needed to access the Session object from within my HttpHandler to check if a value existed, however the HttpContext.Session object was always null! After several minutes of pulling my hair out I discovered I simply needed to implement an additional 'marker' Interface. As I only needed Read Only access to the session object I used IReadOnlySessionState as follows:

public class MyHttpHandler : IHttpHandler,
System.Web.SessionState.IReadOnlySessionState

However if you need write access simply use IRequiresSessionState:

public class MyHttpHandler : IHttpHandler,
System.Web.SessionState.IRequiresSessionState


Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Monday, May 19, 2008 9:38 AM | in .NET C#

Comments

No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 7 and 2 and type the answer here: