?
Solved

HttpContext in Item EventREciver is null.

Posted on 2010-08-17
4
Medium Priority
?
808 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

741 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