Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Generic Handlers & Session

I have an issue with GenericHandler and anonymousIdentification.

Basically if <anonymousIdentification enabled="true" /> is turned on in the web config, whenever a JQuery GET/POST request is sent to the server, that request executes under a new user and a new user session.

Is there a way to mitigate this? I need to access the current user's session variables... It is really frustrating!

like image 435
bleepzter Avatar asked Feb 03 '11 17:02

bleepzter


2 Answers

Generic handlers must implement the IReadOnlySessionState interface to access session variables. If you also need to write session variables, implement IRequiresSessionState.

like image 95
Josh Stodola Avatar answered Oct 22 '22 19:10

Josh Stodola


Implement the System.Web.SessionState.IRequiresSessionState interface:

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState 
{   
  public void ProcessRequest(HttpContext context)  
  {      
    context.Session["StackOverflow"] = "overflowing";      
    context.Response.Redirect("~/AnotherPage.aspx");      
  }

}
like image 38
sm.abdullah Avatar answered Oct 22 '22 21:10

sm.abdullah