简体   繁体   English

初始化会员提供者

[英]Initialize Membership Provider

I need to initialize my membership provider, thus I start from calling it like this: 我需要初始化我的会员资格提供者,因此我从这样调用它开始:

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) 

And I call it from my code behind: 我从后面的代码中调用它:

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

In my Web.Config file I have: 在我的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>

As a conclusion, what I want is to get the passwordFormat which declared in my web.config file. 结束语,我想要的是获取在我的web.config文件中声明的passwordFormat
I'm trying to get the passwordFormat with the following command: 我正在尝试使用以下命令获取passwordFormat

Dim myMemPass As New MembershipPasswordFormat

But what I get is the clear(0) value and not the Hashed(1) which is declared in my web.config. 但是我得到的是clear(0)值,而不是在web.config中声明的Hashed(1)
I really don't know what I'm doing wrong (because it is obvious that something is wrong here). 我真的不知道我在做什么错(因为很明显这里出了点问题)。
May I have an assistance? 我可以帮忙吗?

* ADDITIONAL INFORMATION* * 附加信息*

Public membershipProviderWareHouse As New AspNetSqlMembershipProvider

That is for membershipProviderWareHouse which I forgot it. 那是我忘记了的membershipProviderWareHouse

I have made another call for the initialization: 我再次要求初始化:

    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)

Which doesn't seams to work either. 哪一种也不起作用。

Finally I found what I was looking for. 终于,我找到了想要的东西。

Dim cfg As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath) ' ' Get encryption and decryption key information from the configuration. Dim cfg As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath)''从配置中获取加密和解密密钥信息。 Dim membSection As New MembershipSection 昏暗的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

Using this code I get all the values (and the names) of the AspNetSqlMembershipProvider which is declared in web.config file. 使用此代码,我获得了在web.config文件中声明的AspNetSqlMembershipProvider所有值(和名称)。
That is for use from anyone wants to use it. 那是供任何想使用它的人使用的。
Thank you very much for the assistance from @Alexander 非常感谢@Alexander的协助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM