Groups > Asp .Net > ASP dotNET Security > delete user




delete user

delete user
Thu, 3 Apr 2008 02:38:06 +0000
I have this code for deleting a user with a Cancel button or other error, in
CreateUserWizard_CreatingUser. I know there's a statement for backing out of the
Wizard and deleting from the aspnet_ tables, which I will need to use before
also deleting the record from my added-on table (since errors abound when I try
to do it manually, due to the many relationships). I used one example that I
found on the Web but I received an error, I think because the particular piece
of code expected a user name or user ID which hadn't yet been created. 

At any rate, I will appreciate any good suggestions I can get here. 

Protected Sub cuwCreate_CreatingUser(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.LoginCancelEventArgs) Handles cuwCreate.CreatingUser
        ''If Page.IsPostBack Then
        Page.Validate()
        ''If Not Page.IsValid Then e.Cancel = True
        ''End If
        strUserName = cuwCreate.UserName.ToString
        strUserID = Membership.GetUser(strUserName).ProviderUserKey.ToString()
        Using dbConn As New SqlConnection(strConn)
            Dim cmd As New SqlCommand("sp_DeleteUser", dbConn)
            cmd.CommandType = Data.CommandType.StoredProcedure
            'add Parameters to Command (cmd)
            cmd.Parameters.AddWithValue("@UserID", strUserID)
            dbConn.Open()
            dtrReader = cmd.ExecuteReader
            If Not Page.IsValid Or dtrReader.HasRows = False Then e.Cancel =
True''If dtrReader.HasRows = False Then e.Cancel = True
            dtrReader.Close()
            dbConn.Close()
            cmd.Dispose()
            dbConn.Dispose()
        End Using
    End Sub
Post Reply
about | contact