0

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.

user1439618
  • 235
  • 2
  • 5
  • 13

3 Answers3

0

You should interrogate the mcs parameter 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.

dariom
  • 4,413
  • 28
  • 42
  • The MembershipCreateStatus is success. – user1439618 Jun 06 '12 at 13:08
  • 1
    Hmmm... I'm not sure. Does the identity of the Application Pool for your SharePoint web application have appropriate rights in the FBA database? It should be a user in the database and assigned to the `aspnet_Membership_FullAccess` role (or `db_owner`). Try and provide any other relevant details in your question. It might help us answer! – dariom Jun 06 '12 at 13:27
0

The unknown error when registering a user generally means there was an error sending the email. You can check the SharePoint ULS logs for more details. I would check your SharePoint outgoing mail settings.

If you can see the user in FBA UserManagement - then it has been created in the membership database. Have you checked the aspnetdb database to see if the user exists?

Can you login with another FBA user's account? If not it's likely there's a problem with your FBA setup. Make sure the membership entries are in your STS and Central Admin web configs.

Chris Coulson
  • 494
  • 3
  • 10
0

This should probably be a comment, but I don't have the rep to do that yet. This is for anyone who found this question because they were confused about all the other answers that just say to use

Membership.CreateUser() 

to create users in an FBA-enabled SharePoint site.

When you have a web application with multiple authentication providers enabled, you need to specify the provider using:

Membership.Providers[MembershipProvider].CreateUser()

To get the MembershipProvider, you can specify it as a hard-coded string like OP did, or you can get it dynamically using:

SPSite.WebApplication.IisSettings[SPUrlZone].FormsClaimsAuthenticationProvider.MembershipProvider()
Steve
  • 1,903
  • 5
  • 22
  • 30
DDev
  • 1
  • 2