dfang
dfang

Reputation: 1386

Why Membership.CreateUser Failed?

For this overload:

if CreateUser("[email protected]","pwd") , failed with error message :The e-mail address provided is invalid. Please check the value and try again.

but CreateUser("[email protected]","pwd","[email protected]") , succeed!

why?

Upvotes: 2

Views: 546

Answers (1)

Josh
Josh

Reputation: 44906

It may be better to think of the methods like this:

CreateUser(Username, Password);

CreateUser(Username, Password, Email);

Without reflecting the code I couldn't say 100% for sure, but I'll bet those functions just call an internal function that takes in every possible parameter.

So your first call (simplified) is actually:

CreateUser("[email protected]", "pwd", null);

If you have configured your provider to require email address, then clearly null is not valid.

From the MSDN docs:

The SqlMembershipProvider provides an option to require a unique e-mail address for each user. If the RequiresUniqueEmail property is true, you will need to use one of the CreateUser overloads that allows you to specify an e-mail address for the user being created. Otherwise, a MembershipCreateUserException will be thrown.

Upvotes: 2

Related Questions