Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access View State in ashx file

Tags:

c#

asp.net

I am working on a project, i have on ashx handler file, I want to make some ViewState data in my ashx file and then check it on .cs file

How can i achieve this as i can't access ViewState object in my ashx file

like image 545
Syed Salman Raza Zaidi Avatar asked Nov 16 '25 10:11

Syed Salman Raza Zaidi


1 Answers

No you cannot access the data of page in Ashx file because it handler and get executed when the request to page take place.

Instead of viewstate you can make use of Session boject liek this

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
  {
      public void ProcessRequest(HttpContext context)
     {
           context.Session["sessionvariable"] = "value";
     }
  }

or to just readonly acces to session object

public class Handler : IHttpHandler, IReadOnlySessionState
{
   public bool IsReusable { get { return true; } }

   public void ProcessRequest(HttpContext ctx)
   {
       ctx.Response.Write(ctx.Session["fred"]);
   }
}
like image 104
Pranay Rana Avatar answered Nov 18 '25 04:11

Pranay Rana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!