我可以同时使用多个 MembershipProvider 吗?

发布于 2024-08-25 16:18:29 字数 633 浏览 5 评论 0原文

我的 web.config 和登录控件中有多个会员提供程序,

我将根据带有提供程序名称的下拉列表来使用提供程序。

Web.config:

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

在 Login.ascx.cs 中:

我根据下拉列表选择提供程序,如下所示:

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

问题是每当我点击此行时,它总是尝试连接到 MyOwnProvider1,而实际上选择了 MyOwnProvider2!

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔芯 2024-09-01 16:18:29

您遇到的问题的原因是,当应用程序启动时,提供程序在membership元素中标记为defaultProvider,或者遇到的第一个提供程序,从您的web.config开始并向上游移动到根web.config .net Framework/config 目录已初始化,使其成为成员资格提供程序。

将这种行为与以下事实结合起来:所有内置的管道和控件都希望与单个提供商合作,而您uscwap

为了实现这样的功能,您必须实现一个自定义成员资格提供程序,充当多个身份验证源的外观或聚合器,并将其添加为 web.config 中的单个提供程序。

干杯

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

又怨 2024-09-01 16:18:29

是否可以通过这种方式动态选择提供商?我一直认为不会(尽管我从未尝试过),在这种情况下,我猜测当它加载 Membership.Providers 时,它会停在第一个出现的位置,即您的 MyOwnProvider1案件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文