初始化会员提供商

时间:2014-01-13 09:55:30

标签: asp.net sql tsql asp.net-membership membership-provider

我需要初始化我的会员提供者,因此我从这样称呼它开始:

Public Overrides Sub Initialize(name As String, config As NameValueCollection)
            Dim myNewAsp As New AspNetSqlProvider
            If config Is Nothing Then Throw New ArgumentNullException("config")
            If name Is Nothing OrElse name.Length = 0 Then name =" AspNetSqlMembershipProvider"
            If String.IsNullOrEmpty(config("description")) Then
                config.Remove("description")
                config.Add("system.web/Membership", name)
            End If
            MyBase.Initialize(name, config) 

我从后面的代码中调用它:

Dim SC As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection
            membershipProviderWareHouse.Initialize("AspNetSqlMembershipProvider", SC)

在我的Web.Config文件中,我有:

<membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="20">
      <providers >
        <clear/>
        <add
          name="AspNetSqlMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="TMPApplicationServices"
          enablePasswordReset="true"
          passwordFormat="Hashed"
          enablePasswordRetrieval="false"
         requiresQuestionAndAnswer="false"
          passwordStrengthRegularExpression="(?=^.{8,20}$)(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^])(?!.*\s).*$"
          requiresUniqueEmail="true"
          maxInvalidPasswordAttempts="5"
          minRequiredPasswordLength="8"
          minRequiredNonalphanumericCharacters="1"
          passwordAttemptWindow="10"
          applicationName="/" />

      </providers>
    </membership>

作为结论,我想要的是获取在passwordFormat文件中声明的web.config
我正在尝试使用以下命令获取passwordFormat

Dim myMemPass As New MembershipPasswordFormat

但我得到的是clear(0)值,而不是我在web.config中声明的Hashed(1)
我真的不知道我做错了什么(因为很明显这里出了问题) 我可以帮忙吗?

*其他信息*

Public membershipProviderWareHouse As New AspNetSqlMembershipProvider

那是我遗忘的membershipProviderWareHouse

我再次呼吁进行初始化:

    Dim membershipSection As Web.Configuration.MembershipSection = ConfigurationManager.GetSection("system.web/membership")
    Dim sqlProviderName As String = "AspNetSqlMembershipProvider"
    Dim providerConfig As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection
    providerConfig.Add("AspNetSqlMembershipProvider", (DBNull.Value).ToString)
    membershipProviderWareHouse.Initialize(sqlProviderName, providerConfig)

哪种接缝也不起作用。

1 个答案:

答案 0 :(得分:0)

最后我找到了我要找的东西。

Dim cfg As System.Configuration.Configuration = _                       WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath)         “         '从配置中获取加密和解密密钥信息。         Dim membSection作为新的MembershipSection

    Dim srvHandler As New ServerHandler
    Dim aspProvider As New MyNewAspNetSqlMembershipProvider

    membSection = CType(cfg.GetSection("system.web/membership"), MembershipSection)
    membSection.SectionInformation.ConfigSource = "AspNetSqlMembershipProvider"
    machineKey = CType(cfg.GetSection("system.web/machineKey"), MachineKeySection)


    Dim keys As New ArrayList()
    Dim values As New ArrayList()
    Dim count As Integer = membSection.Providers.Item(0).Parameters.Keys.Count
    For r As Integer = 0 To count - 1
        keys.Add(membSection.Providers.Item(0).Parameters.Keys.Item(r))
        values.Add(membSection.Providers.Item(0).Parameters.GetValues(r))
    Next

使用此代码,我获得了在web.config文件中声明的AspNetSqlMembershipProvider的所有值(和名称)。
这是任何人都想使用它 非常感谢@Alexander提供的帮助