C# 创建会员用户时出错“提供的密码答案无效”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1445709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 16:36:54  来源:igfitidea点击:

Error while creating a Membership user "The password-answer supplied is invalid"

c#asp.netsqlasp.net-membership

提问by Or Betzalel

I tried creating a new user using CreateUser method. but when I click create user button I get this weird error : "The password-answer supplied is invalid".

我尝试使用 CreateUser 方法创建一个新用户。但是当我点击创建用户按钮时,我收到这个奇怪的错误:“提供的密码答案无效”。

I already tried putting a strong password (123$567) or a normal password(1234). I doubt it has anything to do with the password strength because that would throw a different exception.

我已经尝试过设置强密码 (123$567) 或普通密码 (1234)。我怀疑它与密码强度有什么关系,因为这会引发不同的异常。

Here is my code:

这是我的代码:

Membership.CreateUser(username, password);

Can anyone tell me why is this happening?

谁能告诉我为什么会这样?

回答by spender

In your web.config you probably have the setting

在你的 web.config 你可能有设置

<system.web>
    <membership>
        <providers>
            <add bla="bla" requiresQuestionAndAnswer="true" ...

Could this be the problem?

这可能是问题吗?

回答by cjuk

Using @spender's tip (+1) I found the below worked for me by explicitly stating requiresQuestionAndAnswer="false" in the web.config (I had to add the attribute). I then found I could just use Membership.CreateUser(userName, password, email); to create my user.

使用@spender 的提示 (+1),我发现以下内容对我有用,方法是在 web.config 中明确声明 requiresQuestionAndAnswer="false" (我必须添加属性)。然后我发现我可以只使用 Membership.CreateUser(userName, password, email); 创建我的用户。

<system.web>  
<membership>  
    <providers>  
        <add bla="bla" requiresQuestionAndAnswer="false"/>

回答by Abhi

you need to set parameters in web.config

您需要在 web.config 中设置参数

<system.web>
<membership>
    <providers>
<add name="YOURMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="con"  minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear" applicationName="YourAppName" maxInvalidPasswordAttempts="2147483647"/>

I tried this. Its working Fine. Thanks

我试过这个。它的工作正常。谢谢