MembershipUser.MembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime) Constructor

Creates a new membership user object with the specified property values.

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

'Declaration
Public Sub New ( _
	providerName As String, _
	name As String, _
	providerUserKey As Object, _
	email As String, _
	passwordQuestion As String, _
	comment As String, _
	isApproved As Boolean, _
	isLockedOut As Boolean, _
	creationDate As DateTime, _
	lastLoginDate As DateTime, _
	lastActivityDate As DateTime, _
	lastPasswordChangedDate As DateTime, _
	lastLockoutDate As DateTime _
)
'Usage
Dim providerName As String
Dim name As String
Dim providerUserKey As Object
Dim email As String
Dim passwordQuestion As String
Dim comment As String
Dim isApproved As Boolean
Dim isLockedOut As Boolean
Dim creationDate As DateTime
Dim lastLoginDate As DateTime
Dim lastActivityDate As DateTime
Dim lastPasswordChangedDate As DateTime
Dim lastLockoutDate As DateTime

Dim instance As New MembershipUser(providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
public MembershipUser (
	String providerName, 
	String name, 
	Object providerUserKey, 
	String email, 
	String passwordQuestion, 
	String comment, 
	boolean isApproved, 
	boolean isLockedOut, 
	DateTime creationDate, 
	DateTime lastLoginDate, 
	DateTime lastActivityDate, 
	DateTime lastPasswordChangedDate, 
	DateTime lastLockoutDate
)
public function MembershipUser (
	providerName : String, 
	name : String, 
	providerUserKey : Object, 
	email : String, 
	passwordQuestion : String, 
	comment : String, 
	isApproved : boolean, 
	isLockedOut : boolean, 
	creationDate : DateTime, 
	lastLoginDate : DateTime, 
	lastActivityDate : DateTime, 
	lastPasswordChangedDate : DateTime, 
	lastLockoutDate : DateTime
)
Not applicable.

Parameters

providerName

The ProviderName string for the membership user.

name

The UserName string for the membership user.

providerUserKey

The ProviderUserKey identifier for the membership user.

email

The Email string for the membership user.

passwordQuestion

The PasswordQuestion string for the membership user.

comment

The Comment string for the membership user.

isApproved

The IsApproved value for the membership user.

isLockedOut

true to lock out the membership user; otherwise, false.

creationDate

The CreationDateDateTime object for the membership user.

lastLoginDate

The LastLoginDateDateTime object for the membership user.

lastActivityDate

The LastActivityDateDateTime object for the membership user.

lastPasswordChangedDate

The LastPasswordChangedDateDateTime object for the membership user.

lastLockoutDate

The LastLockoutDateDateTime object for the membership user.

Exception typeCondition

ArgumentException

providerName is a null reference (Nothing in Visual Basic).

-or-

providerName is not found in the Providers collection.

Creating a new MembershipUser object does not add a new membership user object to the membership data store. To add a new membership user to the membership data store, use the CreateUser method. Note that the CreateUser method returns a MembershipUser object for the membership user added to the data store.

MembershipUser objects can be constructed in application code for use with the UpdateUser method. Alternatively, you can also pass a MembershipUser object returned from the CreateUser, GetUser, GetAllUsers, FindUsersByName, or FindUsersByEmail method to the UpdateUser method as well.

MembershipUser objects are also commonly constructed by membership-provider implementations for the CreateUser, GetUser, GetAllUsers, FindUsersByName, and FindUsersByEmail methods.

The name, email, and passwordQuestion parameters are all trimmed before being used.

The following code example shows an implementation of the CreateUser method for a membership provider. The method constructs a MembershipUser object that is returned when the user is successfully added to the data store.

Public Overrides Function CreateUser(ByVal username As String, _
ByVal password As String, _
ByVal email As String, _
ByVal passwordQuestion As String, _
ByVal passwordAnswer As String, _
ByVal isApproved As Boolean, _
ByVal providerUserKey As Object, _
         ByRef status As MembershipCreateStatus) As MembershipUser

    Dim Args As ValidatePasswordEventArgs = _
      New ValidatePasswordEventArgs(username, password, True)

    OnValidatingPassword(args)

    If args.Cancel Then
        status = MembershipCreateStatus.InvalidPassword
        Return Nothing
    End If


    If RequiresUniqueEmail AndAlso GetUserNameByEmail(email) <> "" Then
        status = MembershipCreateStatus.DuplicateEmail
        Return Nothing
    End If

    Dim u As MembershipUser = GetUser(username, False)

    If u Is Nothing Then
        Dim createDate As DateTime = DateTime.Now

        If providerUserKey Is Nothing Then
            providerUserKey = Guid.NewGuid()
        Else
            If Not TypeOf providerUserKey Is Guid Then
                status = MembershipCreateStatus.InvalidProviderUserKey
                Return Nothing
            End If
        End If

        Dim conn As OdbcConnection = New OdbcConnection(ConnectionString)
        Dim cmd As OdbcCommand = New OdbcCommand("INSERT INTO Users " & _
              " (PKID, Username, Password, Email, PasswordQuestion, " & _
              " PasswordAnswer, IsApproved," & _
              " Comment, CreationDate, LastPasswordChangedDate, LastActivityDate," & _
              " ApplicationName, IsLockedOut, LastLockedOutDate," & _
              " FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, " & _
              " FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart)" & _
              " Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", conn)

        cmd.Parameters.Add("@PKID", OdbcType.UniqueIdentifier).Value = providerUserKey
        cmd.Parameters.Add("@Username", OdbcType.VarChar, 255).Value = username
        cmd.Parameters.Add("@Password", OdbcType.VarChar, 255).Value = EncodePassword(password)
        cmd.Parameters.Add("@Email", OdbcType.VarChar, 128).Value = email
        cmd.Parameters.Add("@PasswordQuestion", OdbcType.VarChar, 255).Value = passwordQuestion
        cmd.Parameters.Add("@PasswordAnswer", OdbcType.VarChar, 255).Value = EncodePassword(passwordAnswer)
        cmd.Parameters.Add("@IsApproved", OdbcType.Bit).Value = isApproved
        cmd.Parameters.Add("@Comment", OdbcType.VarChar, 255).Value = ""
        cmd.Parameters.Add("@CreationDate", OdbcType.DateTime).Value = createDate
        cmd.Parameters.Add("@LastPasswordChangedDate", OdbcType.DateTime).Value = createDate
        cmd.Parameters.Add("@LastActivityDate", OdbcType.DateTime).Value = createDate
        cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = pApplicationName
        cmd.Parameters.Add("@IsLockedOut", OdbcType.Bit).Value = False
        cmd.Parameters.Add("@LastLockedOutDate", OdbcType.DateTime).Value = createDate
        cmd.Parameters.Add("@FailedPasswordAttemptCount", OdbcType.Int).Value = 0
        cmd.Parameters.Add("@FailedPasswordAttemptWindowStart", OdbcType.DateTime).Value = createDate
        cmd.Parameters.Add("@FailedPasswordAnswerAttemptCount", OdbcType.Int).Value = 0
        cmd.Parameters.Add("@FailedPasswordAnswerAttemptWindowStart", OdbcType.DateTime).Value = createDate

        Try
            conn.Open()

            Dim recAdded As Integer = cmd.ExecuteNonQuery()

            If recAdded > 0 Then
                status = MembershipCreateStatus.Success
            Else
                status = MembershipCreateStatus.UserRejected
            End If
        Catch e As OdbcException
            ' Handle exception.

            status = MembershipCreateStatus.ProviderError
        Finally
            conn.Close()
        End Try


        Return GetUser(username, False)
    Else
        status = MembershipCreateStatus.DuplicateUserName
    End If

    Return Nothing
End Function

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: