Need to access session variables in an ashx?

Just a quick note if you need to access session variables from an ashx, you need to implement SessionState.IRequiresSessionState or IReadOnlySessionState if you only need to read the vars

In your ashx change

Public Class yourclass :     Implements IHttpHandler

    Implements SessionState.IRequiresSessionStat

to

Public Class yourclass

Implements IHttpHandler

    Implements SessionState.IRequiresSessionStat

This entry was posted by nerdboy on Friday, January 16th, 2009 at 5:58 pm and is filed under asp.net. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response below, or trackback from your own site.

Show/Hide Comments (4)

4 Reader Comments (Reply Now)

  1. April 30th, 2009

    @ 1:47 am

    Jeff posted:

    This was excellent. Exactly correct fix to enable session state variables. Thank you.

  2. March 26th, 2010

    @ 2:37 pm

    Tee posted:

    what would I change this to?

    using System;
    using System.Web;

    public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = “text/plain”;

    context.Response.Write(Convert.ToString(HttpContext.Current.Session["pichash"]));
    }

    public bool IsReusable {
    get {
    return false;
    }
    }

    }

  3. August 3rd, 2010

    @ 4:21 am

    bashkutty posted:

    This is only working in IE . It is not working in Mozilla,Chrome,safari and Opera.
    Any help can be appreciated.

  4. August 13th, 2010

    @ 7:38 pm

    admin posted:

    @bashkutty – it’s server-side so shouldn’t matter what browser you’re using

Leave a Reply

(Required)
(Required)