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.
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 !