将成员身份默认提供程序设置读入数据表或 C# 列表

本文关键字:数据表 列表 设置 程序 身份 成员 默认 | 更新日期: 2023-09-27 18:27:50

<membership defaultProvider="SqlMembershipProvider">
      <providers>
        <clear />
        <add 
          name="SqlMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
          connectionStringName="myConnectionStringName" 
          enablePasswordRetrieval="true" 
          enablePasswordReset="true" 
          requiresQuestionAndAnswer="false" 
          applicationName="myApplicationName" 
          requiresUniqueEmail="false" 
          passwordFormat="Clear" 
          maxInvalidPasswordAttempts="10" 
          minRequiredPasswordLength="4" 
          minRequiredNonalphanumericCharacters="0" 
          passwordAttemptWindow="10" 
          passwordStrengthRegularExpression="" />
      </providers>
    </membership>

我在应用程序中有上述设置。配置文件,我可以删除或添加到这些设置中。现在,在我的应用程序中,我想将所有可用设置及其相应的值读取到 DataTable 或 C# 中,然后我可以加载和使用它们。

将成员身份默认提供程序设置读入数据表或 C# 列表

从 app.config 读取使用:

ConfigurationManager.AppSettings["SqlMembershipProvider"]

同时使用了这个解决方案

private class MembershipSetting
    {
        public string settingName { get; set; }
        public string settingValue{ get; set; }
    }
    private void GetMembershipSetting()
    {
        var settings = new List<MembershipSetting>
                            {
                                new MembershipSetting {settingName = "Dafult Membership Provider", settingValue = Membership.Provider.ToString() },
                                new MembershipSetting {settingName = "Minimum Required Password Length", settingValue = Membership.MinRequiredPasswordLength.ToString(CultureInfo.InvariantCulture) },
                                new MembershipSetting {settingName = "Minimum Required Non Alphanumeric Characters",settingValue = Membership.MinRequiredNonAlphanumericCharacters.ToString(CultureInfo.InvariantCulture)},
                                new MembershipSetting {settingName = "Password reset enabled", settingValue = Membership.EnablePasswordReset.ToString()},
                                new MembershipSetting {settingName = "Maximum Invalid Password Attempts",settingValue = Membership.MaxInvalidPasswordAttempts.ToString(CultureInfo.InvariantCulture) },
                                new MembershipSetting {settingName = "Attempt windows",settingValue = Membership.PasswordAttemptWindow.ToString(CultureInfo.InvariantCulture)}
                            };
    }