Solved

HttpContext in Item EventREciver is null.

Posted on 2010-08-17
4
720 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Work Over Net is a new and very powerful collaboration product. With its new easy interface it is becoming very competitive to other similar products like webex and office interactive. WON 2010 have the standard business tools needed for multi-offic…
SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now