0

In ashx: I'm putting data in list of entities & assinging it to session.

context.Session["objList"] = myEntityCollection;

I want to get this Session through response; in code behind. How it is achieved?

context.Response.ContentType = ???
.....
context.Response.Write(context.Session["objList"]);
mike44
  • 802
  • 5
  • 15
  • 36

2 Answers2

2

Hi if I understand you correctly. To access session data in an ashx file you need to implement the interface IRequiresSessionState

public class ExampleHttpHandler : IHttpHandler, IRequiresSessionState
{
    public bool IsReusable
    {
        get
        {
            return false;
        }
    } 

    public void ProcessRequest(HttpContext context)
    {    
        context.Session["test"] = "test";
        context.Response.Write(context.Session["test"]);
    }
}
  • Thanks for reply. But I'm already using that. The problem was that instead of getting object I was getting name of the object in code behind. – mike44 Oct 18 '12 at 15:31
0

Serialize object to JSON, return serialized string with response and use application/json ContentType

Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68