Search code examples
c#asp.net-mvc-4extendsimplemembership

ASP.Net simple membership login with email or username


In my app I want to enable login with email or username. I found this solution , which is extending the simpleMembershiProvider. In this solution there is stated, that I have to register this new membership provider in web.config file but I am unable to find any guide how to do it, so I would be thankful for any instructions how to register the extended provider or for any other solution how to enable login with email or username.

Thank you in advance.


Solution

  • Add this to your web.config under System.Web and tweak the settings in that configuration to match your requirements.

    <membership defaultProvider="AccountMembershipProvider">
      <providers>
        <clear/>
        <add name="AccountMembershipProvider" type="Yourcustomclasswithnamespace" connectionStringName="yourdatabaseconnectionstringname" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="yourappname"/>
      </providers>
    </membership>