0

I am trying to ensure user through web.EnsureUser for FBA users. Here is my code snipplet. as an example :

string fbUsername = "i:0#.f|ie-fbamembership|userlogin";
SPUser userSP = site.RootWeb.EnsureUser(fbUsername);

But i get an error user does not exists. But i can surely add this user to the site collection manually.

But could not add the user through code (programatically).

Any ideas? i could not find a solution for this in the net.

  • S.R.G SharePoint Developer
Ilya
  • 29,135
  • 19
  • 110
  • 158

1 Answers1

0

I'm very late to this question, but I had the same problem today and a colleague of mine finally found a solution.

I just use the AllowUnsafeUpdates property of my SPWeb object and write :

web.AllowUnsafeUpdates = true;
oUser = web.EnsureUser(userId);

In my case, userId is from a PeoplePicker, I construct it like this :

PickerEntity selectedEntity = (PickerEntity)peEditor.ResolvedEntities[i];
string userId = selectedEntity.Key;

Hope it can helps someone !

AlexB
  • 7,302
  • 12
  • 56
  • 74