开发者

Can I use multiple MembershipProviders at one time?

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[dro开发者_开发技巧pDownList.SelectedItem.Text];

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

Any ideas?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜