ASP.NET Membership Create User without requiresQuestionAndAnswer

前端 未结 3 461
醉梦人生
醉梦人生 2020-12-18 22:04

How can I use the CreateUser method in the Membership class without having to assign a question and answer?

I have disabled it in the web.config with the following s

相关标签:
3条回答
  • 2020-12-18 22:22

    As another answerer mentioned, you just pass null in instead of "", or string.Empty.

    When I first discovered this I though that the developers hadn't heard of string.IsNullOrEmpty, and that we were venturing into WTF territory.

    But of course, in their wisdom, they realised that null is conceptually different to an empty string, and in this case, when dealing with input from a user, we want to tell them their question is invalid if it's not specified.

    0 讨论(0)
  • 2020-12-18 22:26

    you need to set parameters in 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

    0 讨论(0)
  • 2020-12-18 22:29

    I haven't tried this, but have you tried just passing null for those two parameters?

    0 讨论(0)
提交回复
热议问题