Question

I've been able to call Membership.CreateUser which has created the necessary Membership tables within my database, but it hasn't added the newly created user into the Users table and the MembershipCreateStatus = InvalidAnswer - not sure what this means.

public void Register(Register register)
        {
            var member = new System.Web.Providers.DefaultMembershipProvider();
            object guid = Guid.NewGuid();
            MembershipCreateStatus status;

            member.CreateUser(register.Username, register.Password, "", "", "", true, guid, out status);

        }

Configuration:

<profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
Was it helpful?

Solution

The answer here are based on our discussion.

I assume that you have this specified this in your web.config as enablePasswordRetrieval="false" from your comment

Then this code will work for you

try
{
    object guid = Guid.NewGuid();
    MembershipCreateStatus status;
    MemberShipUser member = Membership.CreateUser(register.Username, register.Password, "an email address here", null, null, true, guid, out status);
}
catch(MembershipCreateUserException ex)
{
    //handle exceptions
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top