You try and use Request.Session in a .ashx handler and it is null. (You probably get a System.NullReferenceException – Object reference not set to an instance of an object).

Make sure you implement the System.Web.SessionState.IRequiresSessionState interface if you want to read/write Session data or the System.Web.SessionState.IReadOnlySessionState interface if only need to read Session data. Your code should look like the following:


using System;
using System.Web;
using System.Web.SessionState;

public class Handler : IHttpHandler, IRequiresSessionState {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}

public bool IsReusable {
get {
return false;
}
}

}

 

3 Responses to Session is null in an ashx generic handler

  1. maor p says:

    great post.
    well done

  2. Govind says:

    Good post, Thanks for help.

  3. eshanka says:

    Awesome u saved alt of my time :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

2,918 Spam Comments Blocked so far by Spam Free Wordpress

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>