Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用web.config在自定义成员身份中设置minRequiredPasswordLength_C#_Asp.net_Web Config_Membership Provider - Fatal编程技术网

C# 使用web.config在自定义成员身份中设置minRequiredPasswordLength

C# 使用web.config在自定义成员身份中设置minRequiredPasswordLength,c#,asp.net,web-config,membership-provider,C#,Asp.net,Web Config,Membership Provider,我在项目中有CustomMembership类,并在类中使用此代码: private static int _MinRequiredPasswordLength; public static int MinRequiredPasswordLength { set { _MinRequiredPasswordLength = value; } get { return _MinRequiredPasswordLength; } } 并在web.co

我在项目中有CustomMembership类,并在类中使用此代码:

private static int _MinRequiredPasswordLength;
public static int MinRequiredPasswordLength
    {
        set { _MinRequiredPasswordLength = value; }
        get { return _MinRequiredPasswordLength; }
    }
并在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>
但是得到“0”!我想得到“6”。

试试:

MinRequiredPasswordLength.Text = @CustomMembership.MinRequiredPasswordLength
尝试:

尝试:

尝试:


如果您是从抽象的
MembershipProvider
类派生的,则应该重写
MembershipProvider.Initialize
config
集合将包含所有配置属性,您可以使用它们设置属性,包括
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; }
}

如果您是从现有提供程序派生的,例如
SqlMembershipProvider
,那么您可以简单地使用
MinRequiredPasswordLength

的基类实现。如果您是从抽象
成员身份提供程序
类派生的,则应该重写
成员身份提供程序。初始化
config
集合将包含所有配置属性,您可以使用它们设置属性,包括
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; }
}

如果您是从现有提供程序派生的,例如
SqlMembershipProvider
,那么您可以简单地使用
MinRequiredPasswordLength

的基类实现。如果您是从抽象
成员身份提供程序
类派生的,则应该重写
成员身份提供程序。初始化
config
集合将包含所有配置属性,您可以使用它们设置属性,包括
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; }
}

如果您是从现有提供程序派生的,例如
SqlMembershipProvider
,那么您可以简单地使用
MinRequiredPasswordLength

的基类实现。如果您是从抽象
成员身份提供程序
类派生的,则应该重写
成员身份提供程序。初始化
config
集合将包含所有配置属性,您可以使用它们设置属性,包括
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; }
}

如果您是从现有提供程序派生的,例如
SqlMembershipProvider
,然后,您可以简单地使用
MinRequiredPasswordLength

的基类实现。您有“0”,因为您从未为公共属性设置值
MinRequiredPasswordLength
我在web中设置了它。配置您有“0”,因为您从未为公共属性设置值
MinRequiredPasswordLength
我在中设置了它web.config您有“0”,因为您从未为公共属性设置值
MinRequiredPasswordLength
我在web.config中设置了此值。您有“0”,因为您从未为公共属性设置值
MinRequiredPasswordLength
我在web.config中设置了此值。请帮助我从配置[“MinRequiredPasswordLength”]@shahinko-基本上,您可以使用
Int32.TryParse
解析配置[“minRequiredPasswordLength”]。然后决定如果配置参数不存在或不是有效的整数,您要做什么-可能需要抛出ProviderException或ConfigurationErrorsException。请帮助我从config[“minRequiredPasswordLength”]获取它。@shahinko-基本上您可以使用
Int32.TryParse
来解析配置[“minRequiredPasswordLength”]。然后确定如果配置参数不存在或不是有效整数,您要执行的操作-可能需要抛出ProviderException或ConfigurationErrorsException。请帮助我从配置[“minRequiredPasswordLength”]获取它@shahinko-基本上你可以使用
Int32.TryParse
来解析配置[“minRequiredPasswordLength”]。然后决定如果配置参数不存在,或者不是有效的整数,你要做什么-可能你会想抛出ProviderException或ConfigurationErrorsException。请帮助我从config[”获取它minRequiredPasswordLength“]。@shahinko-基本上您可以使用
Int32.TryParse
来解析配置[“minRequiredPasswordLength”]。然后决定如果配置参数不存在或不是有效整数,您要做什么-可能需要抛出ProviderException或ConfigurationErrorsException。