I'm trying to create user in SharePoint 2010 using FBA (Forms Based Authentication). I followed the steps in this article to configure FBA: http://donalconlon.wordpress.com/2010/02/23/configuring-forms-base-authentication-for-sharepoint-2010-using-iis7/
Then I uploaded the FBA package http://sharepoint2010fba.codeplex.com/. Web part loaded normally, but the user is not created. If you try to create a user it gives an unknown error.
After that I tried to create authorization form by myself. The code below handles the registration event:
MembershipCreateStatus mcs = new MembershipCreateStatus();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://makovkasp:30763/"))
using (SPWeb spWeb = site.OpenWeb())
{
try
{
MembershipUser membershipUser =
Membership.Providers["FBAMembershipProvider"].CreateUser(txtLogin.Text,
txtPassword.Text,
txtEmail.Text,
txtSecretQuestion.Text,
txtAnswer.Text, true, null, out mcs);
spWeb.AllowUnsafeUpdates = true;
SPUser spUser = spWeb.EnsureUser(txtLogin.Text);
SPGroup spGroup = spWeb.Groups[2];
spGroup.AddUser(spUser);
spGroup.Update();
}
catch (Exception ex)
{
System.Console.WriteLine(ex.ToString());
}
}
});
After this code is executed, the user creates in SharePoint (I can see it in FBA UserManagement). But it isn't created in FBA database. So, I can't sign in under it's account. Anyone knows how to do it?
Thanks.
You should interrogate the
mcsparameter value after your code is executed. It might indicate why the user account was not created. The MembershipCreateStatus enumeration should show why the user was not saved successfully by the membership provider.