ASP.Net Session State Issue with HTTPHandler

When you are using ASP.Net Sessions and try to utilize HTTPHandler you will face Issues with Session State. some time you will get page break issues as well. To avoid the issues with HTTPHandlers you need to understand the SessionState Marker Interface.

The System.Web.SessionState namespace supplies classes and interfaces that enable storage of data specific to a single client within a Web application on the server. The session-state data is used to give the client the appearance of a persistent connection with the application. State information can be stored within local process memory or, for Web farm configurations, it can be stored out of process using either the ASP.NET State service or a Microsoft SQL Server database.
Session state can be used with clients that do not support cookies. ASP.NET can be configured to encode a session ID in the URL string that is transmitted between the client and the server.

IRequiresSessionState Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.

public interface IRequiresSessionState;

Implement the IRequiresSessionState interface in your custom HTTP handler to identify that your handler requires read and write access to session-state values.
The following code example examines the current HTTP Handler property to determine whether it requires read and write access to session-state values.

bool requiresSession = false;
if (Context.Handler is IRequiresSessionState)
requiresSession = true;

This implementation will resolve the issues with the session state in HTTPHandler.

2 Comments