Which is fine because the UserName can simply be a Guid. But the real problem is that this code is never reached anyway. For debugging I put a breakpoint at this line. And my app never stops at this point while debugging.
If the UserName field is visible on the registration page the registration is successful. However the username is set to whatever the user typed in. If I set the visible property of the UserName textbox control to "false" hoping to set this value in the
CreateUserWizard1_CreatingUser event my registration is unsuccessful and I get the following error message
Your account was not created. Please try again.
I'm sure I'm missing something easy here. But why doesn't CreateUserWizard1_CreatingUser fire like I expect?
hmm... you do have the CreatingUser event bound to the object right?
To check open the page in the designer, select the control and then view the events in the properties window. Make sure you have the control bound to the CreatingUser event.
Can you explain the purpose of the above section of code?
If someone goes to the password recovery page, after logging out their username shows in the box. and from the logic of your handling of the email as username, i don't know what this section of code is supposed to do.
if (string.IsNullOrEmpty(username))
{
lblWarning.Text = "The submitted email does not exist";
return;
}
if (username != null) {
//we have an email address
Session["email"] = PasswordRecovery1.UserName;
PasswordRecovery1.UserName = username;
}
else if (!String.IsNullOrEmpty(PasswordRecovery1.UserName)) {
//we have a userName
MembershipUser user = Membership.GetUser(PasswordRecovery1.UserName);
PasswordRecovery1.UserName = user.Email;
Session["email"] = user.Email;
}
}
You might also want to consider adding this:
if (string.IsNullOrEmpty(username))
{ // send a message to a blank warning label on the page
WarningLabel.Text = "The submitted email does not exist";
return;
}
to the password recovery, if someone enters their email in wrong or an email that doesn't exist, an exception is thrown.
Can you explain the purpose of the above section of code?
If someone goes to the password recovery page, after logging out their username shows in the box. and from the logic of your handling of the email as username, i don't know what this section of code is supposed to do.
Darpa, this code was written quite a while ago for me, your best bet would be to wire it up and step through it. Sorry.
if (string.IsNullOrEmpty(username))
{
lblWarning.Text = "The submitted email does not exist";
return;
}
if (username != null) {
//we have an email address
Session["email"] = PasswordRecovery1.UserName;
PasswordRecovery1.UserName = username;
}
else if (!String.IsNullOrEmpty(PasswordRecovery1.UserName)) {
//we have a userName
MembershipUser user = Membership.GetUser(PasswordRecovery1.UserName);
PasswordRecovery1.UserName = user.Email;
Session["email"] = user.Email;
}
}
You might also want to consider adding this:
if (string.IsNullOrEmpty(username))
{ // send a message to a blank warning label on the page
WarningLabel.Text = "The submitted email does not exist";
return;
}
to the password recovery, if someone enters their email in wrong or an email that doesn't exist, an exception is thrown.
This is true Darpa, you should ensure that you are trapping the logic. again since this has been such a long time, I can only guess that it was not production ready when I posted it. Thanks for the catch.
I tried to follow but I got into one of the problem that is my Email was duplicated. It turn out that the ASP_User table created 2 records for the same user. One for the membership and the other one for the profile. How can I solve this problem??
Minhajkk
Member
65 Points
13 Posts
Re: Using Email as UserName
Sep 16, 2006 02:57 PM|LINK
ok,
we are using email address as a user name and user name will be never change.
engwar
Member
226 Points
96 Posts
Re: Using Email as UserName
Aug 24, 2007 02:58 AM|LINK
radmanmm,
Thanks for the great work. I've got this working 99%. I am able to log in using the email address instead of the custom user name.
Two questions though regarding this section of code...
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e) { CreateUserWizard1.UserName = this.firstName.Text + "." + this.lastName.Text + "." + Guid.NewGuid().ToString(); }1) I get the following error with the above code when compiling
'Register' does not contain a definition for 'firstName'
I can compile by replacing it with the following line...
CreateUserWizard1.UserName =Guid.NewGuid().ToString();
Which is fine because the UserName can simply be a Guid. But the real problem is that this code is never reached anyway. For debugging I put a breakpoint at this line. And my app never stops at this point while debugging.
If the UserName field is visible on the registration page the registration is successful. However the username is set to whatever the user typed in. If I set the visible property of the UserName textbox control to "false" hoping to set this value in the CreateUserWizard1_CreatingUser event my registration is unsuccessful and I get the following error message
Your account was not created. Please try again.
I'm sure I'm missing something easy here. But why doesn't CreateUserWizard1_CreatingUser fire like I expect?
radmanmm
Member
178 Points
62 Posts
Re: Using Email as UserName
Aug 24, 2007 03:08 AM|LINK
hmm... you do have the CreatingUser event bound to the object right?
To check open the page in the designer, select the control and then view the events in the properties window. Make sure you have the control bound to the CreatingUser event.
engwar
Member
226 Points
96 Posts
Re: Using Email as UserName
Aug 24, 2007 02:05 PM|LINK
D'oh!
That was indeed the problem. Thanks.
Again, thanks also for providing the code samples. Sure is a great solution!
cartch2008
Member
40 Points
71 Posts
Re: Using Email as UserName
Mar 31, 2008 04:56 PM|LINK
How are you preventing the same email address from being used more than once?
radmanmm
Member
178 Points
62 Posts
Re: Using Email as UserName
Mar 31, 2008 09:23 PM|LINK
the provider has an attribute for requiring unique emails.
Darpa
Member
64 Points
17 Posts
Re: Using Email as UserName
Apr 15, 2008 09:00 PM|LINK
Can you explain the purpose of the above section of code?
If someone goes to the password recovery page, after logging out their username shows in the box. and from the logic of your handling of the email as username, i don't know what this section of code is supposed to do.
You might also want to consider adding this:
radmanmm
Member
178 Points
62 Posts
Re: Using Email as UserName
Apr 15, 2008 10:26 PM|LINK
Darpa, this code was written quite a while ago for me, your best bet would be to wire it up and step through it. Sorry.
This is true Darpa, you should ensure that you are trapping the logic. again since this has been such a long time, I can only guess that it was not production ready when I posted it. Thanks for the catch.
kenmaster
Member
2 Points
5 Posts
Re: Using Email as UserName
Apr 18, 2008 04:19 AM|LINK
HI there,
I tried to follow but I got into one of the problem that is my Email was duplicated. It turn out that the ASP_User table created 2 records for the same user. One for the membership and the other one for the profile. How can I solve this problem??
Thanks you all
Ken
cartch2008
Member
40 Points
71 Posts
Re: Using Email as UserName
Apr 28, 2008 06:53 PM|LINK
radmanmm...can' you point me to where this might be? I don't see it
sorry, found it...requiresUniqueEmail
="true"