1

Using both synchronous and asycnhronous event handlers (itemAdded and itemAdding), I have been unable to add a user to my Sharepoint 2010 site - using Forms Based Authentication (which I know to be properly setup and working because it has been working perfectly from the Sharepoint UI from what I can tell)

Calling Membership.CreateUser is not working and constantly throws an exception of "object reference not set to an instance of an object". Debugging and looking into Membership, it is clear that something is wrong. Most members are null or throw exceptions as well. I know Membership doesn't have this issue in an Application Page (I can add users, add them to groups, etc.. from an Application page, but it fails inside of an event handler). We originally thought it was a HttpContext issue, but we can get HttpContext.Current inside itemAdding(), so that might not make much difference.

Any clues? Is it possible to add users to SP2010 within an event handler?

Background: when I add a new row to a list (with an Email column), permissions are granted to the user with the specified email address - if that user doesn't exist I want to create it (again, for Forms Based Authentication)

Ryan Roark
  • 61
  • 6

2 Answers2

0

Im have never done any share point development but it sounds like a cross thread problem.. The event will create a new thread which wont have acces to the thread that contains 'Membership'. try passing it through using a delegate? eg

Object.ItemAdded+= (o, args) => Class.Method(o, args, Membership);
Euclid
  • 880
  • 10
  • 24
  • That is an interesting idea. I don't think I can do this, because I don't have access to the invoking thread's code - so could I create a delegate to be called? On further inspection, I have found this problem to not exist in sites that do not use FBA. So maybe I do have more problems on the FBA setup front. – Ryan Roark Dec 14 '10 at 17:00
0

It seems to me that your httpcontext.current is null. At least i had the same problem and that was the reason. Check this http://kbochevski.blogspot.com/2011/01/accessing-membership-database-inside.html I hope it may be of help

hurbata
  • 9
  • 1