HttpContext in Item EventREciver is null.

hi I  am writing ITemEventReceiver for a document library where I have to use session variable that will be passede acroos web part and the other events.
please find the code .
the ctx.current is null.
how can i get the session in Event receivers?
thanks for your help.
class HandleEventClass : SPItemEventReceiver 
        /* Inharitance of SPItemEventReceiver class */

        #region Global_Declarations

        private HttpContext ctx;
        #endregion Global_Declarations

        #region Overidable Events

        public HandleEventClass() {

            ctx = HttpContext.Current;

public override void ItemAdding(SPItemEventProperties properties)

            if (ctx.Session["isRestore"] == null)
                ctx.Session["isRestore"] = "0";
            flag = true;


Open in new window

Who is Participating?
callazraConnect With a Mentor Author Commented:
got rid of the issue , by using http.runtim.cache

it's by design dear, you can not have http context available for item event receivers.

read this post to understand it fully

it's a series, so that you will know inside out how event handler works in SharePoint.

Vikas Patel.
callazraAuthor Commented:
is there a way to store my session variable or something like that?
Use static collection along with logged in user which you can get from SPContext object and remove it timely by using some logic

hope this will give you some insight, it's not compete but workaround. ;)

if you have farm environment with more then one WFE's then this will not work at that time you need to use persistence storage to go ahead.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.