Read or Write Session value on HTTP Handler file (.ashx)

Posted by Venkat | Labels: ,

How to use Session (ie: read or Write) on HTTPHandler file ie: .ashx file ?

I noticed some post on forums how to get the Session value on (.ashx file). So here is the solution.
By Default if you use Session on handler, the session returns null value. You have to implement the interface to read or write session value on handler file. If there is a situation to read Session value on your Handler file  implement IReadOnlySessionState.

When there is a case, you have to read or write session value in Handler file.
Implement IRequireSessionState.

Here is the code where i implement both IReadOnlySessionState and IRequireSessionState.

Example:

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Web.SessionState; 

public class Handler : IHttpHandler , IReadOnlySessionState  , IRequiresSessionState   {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

1 comments:

  1. Anonymous said...:

    What і don't rеalіzе іs in reаlіty how уou are not reallу а lot more smartlу-favοгed thаn yоu maу be now.
    Үou are so intelligent. Yοu know thus considеrably whеn it comes tο this subjеct, made me fοr my part believe іt from numerous vаrious angles.
    Its like women and men don't seеm to be fascinatеdеxсept it's one thіng to accomplіsh
    with Woman gagа! Yοur own stuffs outstanding. At all times
    taκe care οf it up!

    Feel free to visit my homеpage; game hacks and cracks

Post a Comment

Thanks for the Comments.

PayOffers.in