Question

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:

<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.
I'm trying to get the passwordFormat with the following command:

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.
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.

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.

Was it helpful?

Solution

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 membSection As New 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.
That is for use from anyone wants to use it.
Thank you very much for the assistance from @Alexander

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top