14

如何在 Membership 类中使用 CreateUser 方法而无需分配问题和答案?

我在 web.config 中使用以下设置禁用了它。

requiresQuestionAndAnswer="false"

我需要 CreateUser 方法的状态输出,但重载需要问答。谁能建议我怎么做?

4

3 回答 3

15

我还没有尝试过,但是您是否尝试过为这两个参数传递 null ?

于 2009-02-27T18:25:45.800 回答
6

您需要在 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"/>

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

于 2012-02-22T12:27:39.520 回答
2

正如另一位回答者提到的那样,您只需传入null而不是"", 或string.Empty

当我第一次发现这一点时,我以为开发人员还没有听说过string.IsNullOrEmpty,我们正在冒险进入 WTF 领域。

但是当然,在他们的智慧中,他们意识到这null在概念上与空字符串不同,在这种情况下,当处理来自用户的输入时,我们想告诉他们如果没有指定他们的问题是无效的。

于 2009-11-10T00:33:41.160 回答