When you have multiple membership providers configured, like:
<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />
<add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
Then let's say, for a particular section in the site I want to use SimpleMembershipProvider for auth (the rest of the site will use the default provider i.e. UmbracoMembershipProvider) ... Therefore I need to initialize SimpleMembership with:
WebSecurity.InitializeDatabaseConnection(
Constants.Membership.ConnectionStringName,
Constants.Membership.TableName,
Constants.Membership.UserIdColumnName,
Constants.Membership.UserNameColumnName,
false);
But it seems the above code only works when SimpleMembershipProvider is the defaultProvider. I can't see a way to specify the provider name I want to use? Is this even possible? Or does simplymembership assume you have one membership and role provider defined?
SimpleMembershipProvideris an implementation ofExtendedMembershipProvider. AlthoughWebSecuritywill work with any implementation of the extended provider it has some questionable coupling toSimpleMembershipProviderif used.Basically
SimpleMembershipProviderrequires initialisation viaWebSecurity, otherwise it will throw an exception when the extended membership interface is used. If not initialised then it wraps the defaultASPNETprovider and can be used with the originalMembershipProviderInterface and old schema.The initialisation routine only initialises the default providers, provided they can be cast to the simple provider implementations. So yes you cannot use
SimpleMembershipProviderorSimpleRoleProviderunless they are configured as the default instances.There's some more information about the limitations of
SimpleMembershipProviderhere.There is a work-around. You can use reflection to temporarily swap the provider to the default during initialisation and then switch it back. See BetterMembership.Net for an example of doing exactly that. This library extends
SimpleMembershipProviderspecifically for use in multi-provider systems.