Search code examples
asp.net-mvcasp.net-mvc-4membership-provider

Understanding the CreateUser method of MembershipUser


In the following method which comes from MembershipUser class

public override MembershipUser CreateUser(string username, string password, 
                                          string email,
                                          string passwordQuestion,
                                          string passwordAnswer, bool isApproved, 
                                          object providerUserKey,
                                          out MembershipCreateStatus status)

can anyone explain me what are following for?

 bool isApproved, object providerUserKey, out MembershipCreateStatus status

I looked up at the following site from microsoft msdn but I couldn't understand properly.


Solution

  • From that documentation:

    isApproved
    Type: System.Boolean
    A Boolean that indicates whether the new user is approved to log on.
    providerUserKey
    Type: System.Object
    The user identifier for the user that should be stored in the membership data store.
    status
    Type: System.Web.Security.MembershipCreateStatus
    A MembershipCreateStatus indicating that the user was created successfully or the reason creation failed.
    

    It seems quite straightforward to me. You could pass isApproved: false to the method if you wanted a user to be created without the ability to log on.

    Looking at the documentation for MembershipCreateStatus you can see that this will return a variety of different error messages specifying exactly why the user creation failed (or was successful).

    As for the providerUserKey, this should be a value to uniquely identify a user, such as an integer id.