Solved

HttpContext in Item EventREciver is null.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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