views:

43

answers:

2

I've got multiple membership providers in my web.config and in my login control,

I am going to use the provider based on a drop down list with the name of the provider.

Web.config:

<system.web>
    <membership>
      <providers>
        <remove clear />
        <add name="MyOwnProvider1" .... />
        <add name="MyOwnProvider2" .... />
      </providers>
    </membership>
  </system.web>

In Login.ascx.cs:

I am selecting the provider based on a drop down list like so:

MembershipProvider provider = Membership.Providers[dropDownList.SelectedItem.Text];

Problem is whenever I hit this line, it always tries to connect to MyOwnProvider1 when in fact MyOwnProvider2 was selected!

Any ideas?

+1  A: 

Is it possible to dynamically select a provider that way? I've always assumed not (though I've never tried it), in this instance I'd guess that when it loads Membership.Providers it stops at the first one it comes to, MyOwnProvider1 in your case.

PhilPursglove
Here's the kicker:When I want to even do: Membership.Providers to get the collection of providers, it gives a Configuration error saying that it was Unable to establish a secure connection!
LB
That means it's actually stopping at the first one and trying to connect to it like you said.
LB
+1  A: 

The cause of the problem you are having is that when the app is spun up, either the provider flagged as defaultProvider in the membership element OR the first provider encountered, starting with your web.config and moving upstream to the root web.config in the .net framework/config directory, is initialized, making it the membership provider.

Couple this behavior with the fact that all of the baked in plumbing and controls are expecting to work with a single provider and you are uscwap.

In order to make something like this work, you are going to have to implement a single custom membership provider that acts as a facade or aggregator for your multiple authentication sources and add that as the single provider in web.config.

Cheers

Sky Sanders