SqlMembershipProvider.CreateUser Method (String, String, String, String, String, Boolean, Object, MembershipCreateStatus)

 

Adds a new user to the SQL Server membership database.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

override CreateUser : 
        username:string *
        password:string *
        email:string *
        passwordQuestion:string *
        passwordAnswer:string *
        isApproved:bool *
        providerUserKey:Object *
        status:MembershipCreateStatus byref -> MembershipUser

Parameters

username
Type: System.String

The user name for the new user.

password
Type: System.String

The password for the new user.

email
Type: System.String

The e-mail address for the new user.

passwordQuestion
Type: System.String

The password question for the new user.

passwordAnswer
Type: System.String

The password answer for the new user.

isApproved
Type: System.Boolean

Whether or not the new user is approved to be validated.

providerUserKey
Type: System.Object

A Guid that uniquely identifies the membership user in the SQL Server database.

status
Type: System.Web.Security.MembershipCreateStatus

One of the MembershipCreateStatus values, indicating whether the user was created successfully.

Return Value

Type: System.Web.Security.MembershipUser

A MembershipUser object for the newly created user. If no user was created, this method returns null.

This method is called by the Membership class to create a new user in the SQL Server database specified in the ASP.NET application's configuration file.

New users are identified with the configured ApplicationName.

If the RequiresUniqueEmail property is set to true, and null or an empty string ("") is specified for the email parameter, the user creation will fail. The user creation will also fail if the RequiresUniqueEmail property is set to true and the value specified for the email parameter is a duplicate of the e-mail address for an existing user in the database for the configured ApplicationName.

The maximum length for the user name is 256 characters. The maximum length for the e-mail address is 256 characters. The maximum length for the password in clear text or after it has been hashed or encrypted is 128 characters.

Other conditions that will cause user creation to fail:

  • The password parameter is null, or an empty string after trimming.

  • The length of the password parameter is less than the value specified in the MinRequiredPasswordLength property.

  • The number of non-alphabetic characters in the password parameter is less than the value specified in the MinRequiredNonAlphanumericCharacters property.

  • The password parameter does not pass the regular expression in the PasswordStrengthRegularExpression property.

  • Custom password-validation code canceled user creation during the ValidatingPassword event.

  • The RequiresQuestionAndAnswer property is true and the passwordAnswer parameter is either null or an empty string after trimming.

  • The passwordAnswer parameter is an empty string.

  • The passwordAnswer parameter is longer than 128 characters.

  • The RequiresQuestionAndAnswer property is true and the password question is either null or an empty string after trimming.

  • The passwordQuestion parameter is an empty string.

  • The passwordQuestion parameter is longer than 256 characters.

  • The providerUserKey parameter set to an object of a type other than System.Guid.

  • The providerUserKey parameter is a duplicate of an existing user key.

  • The username parameter is a duplicate of an existing user name.

Leading and trailing spaces are trimmed from all string parameter values.

The following code example creates a new user for an ASP.NET application configured to use forms authentication and the SqlMembershipProvider. If the user is not created successfully, a message is displayed to the user. Otherwise, the user is redirected to the sign-in page for the application.

System_CAPS_noteNote

This sample calls the SqlMembershipProvider specified as the defaultProvider in the Web.config file using the Membership class. If you need to access the default provider as the type SqlMembershipProvider, you can cast the Provider property of the Membership class. To access other configured providers as a specific provider type, you can access them by their configured name with the Providers property of the Membership class and cast them as the specific provider type.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: