-->

Set active membership provider programmatically

2019-09-09 19:52发布

问题:

I have a web application with custom membership providers. The provider I want to use connects to a Progress database.

I have one page that uses a competely different membership provider. I've tried setting this via the web.config but cannot get it working.

So I was wondering if I could set the membership provider programmatically for this page. I see here that it is possible on some level though this looks pretty hacky. I was hoping there'd be a clean way of doing this one way or another. Everything else on SO or the wider web seems to end in a dead end. This suggests to me that what I'm attempting is not possible but it would be nice to know either way.

Is it possible to simply switch the MembershipProvider at runtime?

回答1:

This is not an ideal solution but you can select a different provider at runtime.

var p = (ProgressMembershipProvider)Membership.Providers["ProgressProvider"];
var user = p.GetUser("Foo", true);