[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 829
  • Last Modified:

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.
Azra
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)
        {  
            
            base.ItemAdding(properties);

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

}

Open in new window

0
callazra
Asked:
callazra
  • 2
  • 2
1 Solution
 
vikas413Commented:
Hi,

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

read this post to understand it fully

http://blogs.msdn.com/b/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx

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

Regards,
Vikas Patel.
0
 
callazraAuthor Commented:
is there a way to store my session variable or something like that?
0
 
vikas413Commented:
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.
0
 
callazraAuthor Commented:
got rid of the issue , by using http.runtim.cache
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now