How to access Session in .ashx file?

c#

Solution

In aspx file:

Session.Add("filename", "Test.txt");

After you have set session value in aspx file. Use following to get the value in ashx file.

In ashx file:

public class ImageHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
      string Name = "";
      if (context.Session["filename"] != null)
         Name = context.Session["filename"].ToString();
    }
}

Problem

I want to access some value(which is already set in.aspx file) in .ashx file. I tried to get that value using querystring, session etc but each time it failed. Can anyone suggest me how can we access session value in .ashx file?

Original source