Reputation: 251
i have CustomMembership class in project and use this code in class:
private static int _MinRequiredPasswordLength;
public static int MinRequiredPasswordLength
{
set { _MinRequiredPasswordLength = value; }
get { return _MinRequiredPasswordLength; }
}
and set membership in web.config
<membership defaultProvider="CustomMembership">
<providers>
<clear />
<add name="CustomMembership" type="Project1.Code.CustomMembership, Project1, Version=1.0.0.0, Culture=neutral" connectionStringName="PConn" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
and use this code for get minRequiredPasswordLength:
MinRequiredPasswordLength.Text = CMembership.MinRequiredPasswordLength.ToString();
but get '0'! I want get '6'.
Upvotes: 0
Views: 966
Reputation: 124814
If you've derived from the abstract MembershipProvider
class, you should override MembershipProvider.Initialize
. The config
collection will contain all the configuration attributes, and you can use them to set your properties including MinRequiredPasswordLength
:
private int _minRequiredPasswordLength;
public override void Initialize(string name, NameValueCollection config)
{
_minRequiredPasswordLength = // get it from config["minRequiredPasswordLength"], with validation and conversion to int.
}
public override MinRequiredPasswordLength
{
get { return _minRequiredPasswordLength; }
}
If you've derived from an existing provider, e.g. SqlMembershipProvider
, then you can simply use the base class implementation of MinRequiredPasswordLength
.
Upvotes: 2
Reputation: 7416
Try :
MinRequiredPasswordLength.Text = @CustomMembership.MinRequiredPasswordLength
Upvotes: 1