Microsoft Entity Framework: Using Multiple Membership Providers12/11/2013
The Membership Framework is used often at Dirigo. We us this framework with many of our websites to set up basic log-in abilities. The fundamental job of a membership provider is to manage the data regarding a site's registered users, and to provide methods for creating users, deleting users, verifying login credentials, changing passwords, and so on. Passwords stored in the membership provider are so secure that even we don't have access to them. This is a good thing because many of those passwords are used elsewhere. No developer, not even Dirigo developers, shoud have access to secure passwords.
We also use the membership provider to set up DirigoEdge log-in permissions. However, with DirigoEdge becoming a more prominent CMS solution for our customers with legacy membership providers, we often encounter membership clashing. The fix takes a bit to figure out. Here is how I deal with the issue.
Multiple membership frameworks can be used on a single website by adding new providers into the Web.config.
<add name="EdgeMembershipProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="EdgeConnection">
<add name="OtherMembershipProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="OtherConnection">
Notice the Default Provider. The key is the set up of the Connection Strings.
Once your Web.config is set up, then you can switch between providers.
var edge = Membership.Providers["EdgeMembershipProvider"];
var other = Membership.Providers["OtherMembershipProvider"];
Since EdgeMembershipProvider is the default provider, then Membership.ValidateUser() is equivalent to edge.ValidateUser(). You can configure as many membership providers as you want in the web.config for your application, but you choose a default provider as part of the setup. If you use the standard Login control, it will only check against that default provider.