|
-
Dec 2nd, 2008, 06:14 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [2008] Asp Membership Provider Set Up for Windows Form, how do I check CreateUser success?
I've got my Windows Form to correctly function with ASP.Net 2.0's membership provider and my membership database that I am using on my Asp.net web application.
The user's get entered just fine through my forms.
However, I when the user creation is completed successfully and successfully added to the declared role, I want to pop up a new Form with the username, email, and default password to hand out to the individual.
How do I check for this event to pop up my form load event?
I tried an If MembershipCreateStatus.Success = True after my user creation but it didn't flag any event.
Should I do a Try Catch block and do an If MembershipCreateStatus = True within that to load up the other form? Or how would I go about accomplishing this?
Also, if I wanted the user to change the default password on their first login I would just pass a check against the CreateDate and LastPasswordChangedDate and if they are = force them to change their password?
-
Dec 2nd, 2008, 06:56 PM
#2
Addicted Member
Re: [2008] Asp Membership Provider Set Up for Windows Form, how do I check CreateUser success?
try displaying the variable membershipcreatestatus as a string in a label or something (temporarily). then you would know which code to use to flag the event properly
-
Dec 2nd, 2008, 10:42 PM
#3
Thread Starter
Addicted Member
Re: [2008] Asp Membership Provider Set Up for Windows Form, how do I check CreateUser success?
I'm pretty sure the MembershipCreateStatus returns a boolean value, problem is I think I may be called it at the wrong point in my code.
-
Dec 3rd, 2008, 11:20 AM
#4
Re: [2008] Asp Membership Provider Set Up for Windows Form, how do I check CreateUser success?
I don't know what your code looks like but surely you call some sort of a method that does the actual member creation? Are you using Membership.CreateUser? Look at its return type, it is MembershipUser. If you get an object back then that is your newly created user and you can assume that the user has been created. Else an exception of type MembershipCreateUserException will be thrown, so you need to handle that.
-
Dec 7th, 2008, 04:44 PM
#5
Thread Starter
Addicted Member
Re: [2008] Asp Membership Provider Set Up for Windows Form, how do I check CreateUser success?
I actually figured it out. I stored the success status into a variable into my call on CreateUser and the user was being created fine, however it was not pulling up the flag.
So I added an else to my if, and I had it post the success value to string if it didn't succeed, or based on how I would have perceived the code to handle the expression if the user creation was not successful.
Oddly enough, the string did trigger and it posted Success. So apparently the flag isn't accessed the same way as how I would have thought it would be. Anyway, here's the solution and the code for anyone interested:
Code:
Dim CreateUser As New MembershipCreateStatus
Membership.CreateUser( _
UserInfo.GetUserName, _
UserInfo.GetUserPassword, _
UserInfo.GetUserEmail, _
SecurityQuestion, _
UserInfo.GetUserSecurityAnswer, _
True, _
CreateUser)
Roles.AddUserToRole(UserInfo.GetUserName, UserRole)
If MembershipCreateStatus.Success.ToString = "Success" Then
frmRegistrationSuccess.txtUserName.Text = UserInfo.GetUserName
frmRegistrationSuccess.txtEmail.Text = UserInfo.GetUserEmail
frmRegistrationSuccess.txtPassword.Text = UserInfo.GetUserPassword
frmRegistrationSuccess.Show()
Else
MessageBox.Show(MembershipCreateStatus.Success.ToString)
End If
Now I just need to pull out the error code to post if the user wasn't created successfully.
Thanks and hope this helps.
-
Dec 8th, 2008, 08:48 AM
#6
Hyperactive Member
Re: [RESOLVED] [2008] Asp Membership Provider Set Up for Windows Form, how do I check CreateUser success?
Another way should be to use the getuser method and check to see if a specific username is found in the userstore. If the value of userInfo is anything other than "NOTHING" then you should have had success.
Code:
Dim usrInfo As MembershipUser = Membership.GetUser(username to be checked)
If usrInfo IsNot NOTHING then
'created successfully
End If
This is also a good way to check if the username has been locked or not yet approved.
Microsoft Office Integration:Useful Database Links:
Connection Strings
Im a pogramar
Iam a programer
I’m a programor
I write code! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|