Solved

HttpContext in Item EventREciver is null.

Posted on 2010-08-17
4
773 Views
Last Modified: 2012-05-10
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
Comment
Question by:callazra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:vikas413
ID: 33461317
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
 

Author Comment

by:callazra
ID: 33461362
is there a way to store my session variable or something like that?
0
 
LVL 6

Expert Comment

by:vikas413
ID: 33461853
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
 

Accepted Solution

by:
callazra earned 0 total points
ID: 33462239
got rid of the issue , by using http.runtim.cache
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is one common problem that all we SharePoint developers share: custom solution deployment. This topic can't be covered fully in this short article, so all I want to do in this one is to review it from a development-to-operations perspectiv…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question