p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 (http://p2p.wrox.com/book-professional-asp-net-3-5-c-vb-isbn-978-0-470-18757-9-388/)
-   -   [newbie] The E-mail supplied is invalid ? (http://p2p.wrox.com/book-professional-asp-net-3-5-c-vb-isbn-978-0-470-18757-9/73303-newbie-e-mail-supplied-invalid.html)

jon80 March 13th, 2009 11:43 AM

[newbie] The E-mail supplied is invalid ?
 
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

[:confused:]

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

Imar March 14th, 2009 03:40 PM

Maybe you entered an e-mail address that is not in a valid format for an e-mail address?

BTW: no need to call ToString() on the Text property; it's already a string.

Cheers,

Imar

jon80 March 14th, 2009 05:47 PM

Quote:

Originally Posted by Imar (Post 237059)
Maybe you entered an e-mail address that is not in a valid format for an e-mail address?

BTW: no need to call ToString() on the Text property; it's already a string.

Cheers,

Imar

Umm...don't think so. The form prompted me for a username/password. See my notes..

Imar March 15th, 2009 06:19 AM

I did of course look at your notes,but the error is coming from the same code that comes with your code so it had to be in there somewhere. It's often a matter of eliminating problems.

Anyway, the problem is in the way you have configured the provider. I'm pretty sure that you have something like requiresUniqueEmail="true" in your web.config; either directly or by inheriting it from system files.

Since this setup requires you to pass a (unique) e-mail address, you get your error when you don't supply an address at all. Simply set it to False and it should work.

Hope this helps,

BTW: were you able to solve the problems with the replies from Lee and me? Some follow up is always appreciated.... ;-)

Imar

jon80 March 15th, 2009 08:58 AM

Quote:

Originally Posted by Imar (Post 237078)
I did of course look at your notes,but the error is coming from the same code that comes with your code so it had to be in there somewhere. It's often a matter of eliminating problems.

Anyway, the problem is in the way you have configured the provider. I'm pretty sure that you have something like requiresUniqueEmail="true" in your web.config; either directly or by inheriting it from system files.

Since this setup requires you to pass a (unique) e-mail address, you get your error when you don't supply an address at all. Simply set it to False and it should work.



Hope this helps,

BTW: were you able to solve the problems with the replies from Lee and me? Some follow up is always appreciated.... ;-)

Imar


Well, the funny thing is that when I wasn't updating any email address this exception was being thrown, hence, the question.

When I walked through the code the exception was being thrown by the Membership.CreateUser. I just did not understand why an invalid email exception was being thrown.

With regards the Logon control and other replies they seem valid although I still have to go through the tutorials again :)

Mahesha999 January 11th, 2012 05:56 PM

Thanks Imar
 
Hi there, thanks Sir for your help.
I did faced the same problem. But I did not figured out that the requiresUniqueEmail was set to true. you were accurate. Great.

(I am the same person who discussed the issue of Resources.axd with you)

simplebhe March 11th, 2013 11:35 PM

Maybe you entered an e-mail address that is not in a valid format for an e-mail address?

Chikelusmith July 20th, 2013 02:15 AM

Yeah i guess that is t what the problem is...


All times are GMT -4. The time now is 02:09 AM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.