JamesP
JamesP

Reputation: 195

Membership.CreateUser keeps throwing 'InvalidAnswer'

I've been trying to use the CreateUser method to add users to my database. One thing I want is that password questions and answers aren't required, and so I have this in my Web.config:

    membership>
                <providers>
                    <clear/>
                    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" 
connectionStringName="CBCFXConnString" 
enablePasswordRetrieval="false" 
enablePasswordReset="true" 
requiresQuestionAndAnswer="false" 
requiresUniqueEmail="false" 
maxInvalidPasswordAttempts="5" 
minRequiredPasswordLength="8" 
minRequiredNonalphanumericCharacters="0" 
passwordAttemptWindow="10" 
applicationName="CBCFX"/>

as you can see, I've set the requiresQuestionAndAnswer to false. This setting has been in my configuration ever since I started programming, and I am just dumbfounded as to why that InvalidAnswer persists when I try adding a user with this line:

fxSMP.CreateUser(userName, passWord, eMail, null, null, true, null, out status);

I've even tried passing empty strings to the question and answer arguments:

string pwQuestion = "";
string pwAnswer = "";

fxSMP.CreateUser(userName, passWord, eMail, pwQuestion, pwAnswer, true, null, out status);

but still nothing. What can I do to make this work?

EDIT: I've gone around the internet some more, and there appears to be an overload method wherein you could only input a UserName, Password and Email. Why does this overload not seem to be available in my instance of SqlMembershipProvider?

Upvotes: 3

Views: 692

Answers (1)

Leo
Leo

Reputation: 14830

In your question I can't see how you are declaring the membership element in the web.config file but make sure you set the defaultProvider attribute...just in case. Also, I'd suggest you to use a different overload of the CreateUser method...

System.Web.Security.Membership.CreateUser(string username, string password, string email)

Edit

Now, since you are using the SqlMembershipProvider this overload will not be available. Why? First, because you are NOT supposed to be calling this method directly on your client code. You should rather use the Membership class. If you set the defaultProvider of the membership element in the web.config file and set the requiresQuestionAndAnswer to false then you shouldn't have any issues whatsoever.

By the way, check out this MSDN Documentation

Upvotes: 3

Related Questions