0

How to send session from .ashx page to .aspx.cs page. I want to send a integer value through session. Plz help me.

Sonali
  • 339
  • 2
  • 3
  • 14

1 Answers1

0

You need to use the IReadOnlySessionState or IRequiresSessionState following in your handler.

Suppose you have a handler name MyHandler then you need to use it as follows

 public class MyHandler : IHttpHandler, IReadOnlySessionState

and in that handler you need to write as follows

 public class MyHandler : IHttpHandler, IReadOnlySessionState
 {

    public void ProcessRequest(HttpContext context)
    {
        context.Session["yourKye"]="test123";
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
 }

and you can use it in you page as normal session

string value=(string)Session["yourKye"];

Some similar questions

  1. How to access Session in .ashx file?
  2. HttpContext.Current.Session is null in Ashx file
  3. Asp.Net Session is null in ashx file

In the ashx.cs file, also "implement" the interface System.Web.SessionState.IReadOnlySessionState or System.Web.SessionState.IRequiresSessionState.

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • For IReadOnlySessionState any namespace is required? – Sonali Feb 11 '14 at 09:13
  • the name spaces are `System.Web.SessionState.IReadOnlySessionState` and `System.Web.SessionState.IRequiresSessionState` – शेखर Feb 11 '14 at 09:16
  • It is not working. string value=(string)Session["yourKye"]; Here string valee store return a null – Sonali Feb 11 '14 at 09:36
  • @Sonali can you put your handler and the page in your question. – शेखर Feb 11 '14 at 09:41
  • @ Șhȇkhaṝ I have used handler to create a captcha. In handler using "Random" i have created a string and then it converted into image. And in my aspx file within Image src I call this ashx page just like Now I want to store the randomly created string in session for validate the captcha. – Sonali Feb 11 '14 at 10:19
  • @Sonali not that your handler will be called after the page_load. The browser will request for the image once it is rendered. You can get the session values after postback. You can not get the value of session before postback. – शेखर Feb 11 '14 at 10:53