I switched to SimpleMembershipProvider
in an ASP.NET MVC 4 app. Everything else is working great but there's this problem...
When I try this code:
var password = Membership.GeneratePassword(Membership.MinRequiredPasswordLength, 0);
MinRequiredPasswordLength
is always 0. The settings defined in the membership provider's Web.config
section are not being read.
Here's the Membership default provider Web.config
section:
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="DefaultConnection"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/Acad" />
</providers>
</membership>
Here's the debug info I get:
Any hints?
Is the SimpleMembershipProvider
so simple that it doesn't even use the Web.config section?
Solution for the moment
To overcome the SimpleMembershipProvider
current limitation, I used this code to grab the value defined in Web.config
:
MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");
var defaultProvider = membershipSection.DefaultProvider;
ProviderSettings providerSettings = membershipSection.Providers[defaultProvider];
var minRequiredPasswordLength = int.Parse(providerSettings.Parameters["minRequiredPasswordLength"]);
type
before seeing your answer. This is the error I get:Provider must implement the class System.Web.Security.MembershipProvider'.
– Sage