Listing 16-9
When I run this code I am getting an error:
Error: System.Web.Security.MembershipCreateUserException: The E-mail supplied is invalid. at System.Web.Security.Membership.CreateUser(String username, String password, String email) at System.Web.Security.Membership.CreateUser(String username, String password) at ASP.default_aspx.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\TestWebSite\Default.aspx:line 8
I realized that this was because there wasn't a specific 'catch' so, anyway the code was updated (ref. Pg.774).
...
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Membership.CreateUser(TextBox1.Text.ToString(), TextBox2.Text.ToString());
Label1.Text = "Successfully created user " + TextBox1.Text;
}
catch (MembershipCreateUserException ex)
{
Label1.Text = "Error: " + ex.ToString();
switch (ex.StatusCode)
{
case MembershipCreateStatus.InvalidEmail:
Label1.Text = "Error: " + "An invalid email address has been updated";
break;
}
}
}
...
However, I'm not sure why this particular exception is being thrown by Membership.CreateUser. Since I'm updating a username and a password.
...
Membership.CreateUser(TextBox1.Text.ToString(), TextBox2.Text.ToString());
...
Related links:
http://msdn.microsoft.com/en-us/libr...reateuser.aspx