Session is null in an ashx generic handler
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
Leave a Reply Cancel reply
-
Calendar
February 2012 M T W T F S S « Feb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 -
Meta






great post.
well done
Good post, Thanks for help.
Awesome u saved alt of my time