I’m running into issues when I try to instantiate a new DefaultMembershipProvider (system.web.providers).
DefaultMembershipProvider _provider = new DefaultMembershipProvider();
After this I would assume settings are loaded from the web.config but this is not the case. For example minRequiredPasswordLength remains 0.
Here’s my membership settings:
<membership>
<providers>
<add applicationName="/"
connectionStringName="MyDB"
enablePasswordRetrieval="false"
enablePasswordReset="true"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</providers>
</membership>
I can create new users via the asp.net configuration tool without problem so my database connection seems ok.
Any ideas?
No need to instantiate it yourself. You should just be able to access the static properties and methods of the
Membershipclass directly (you’ll notice that most of them are static).For instance, this would give you the minimum required password length that you have configured:
You can do a number of other convenient things with the static methods, like getting all your users (with the
GetAllUsersmethod) or updating specific user information (with theUpdateUsermethod).Also, I believe you should have the
typein your membership settings set to