In a recent web project we needed to implement and use custom Membership/Role providers for Active Directory since we hade some specific cases to handle. We hade no real problems creating and using these providers but we ran into a problem with Episerver.
Since the user creation in the system is complex we did not want/could't allow creation/edit from inside Episerver's admin interface. We knew that this is done for the WindowsMembershipProvider, the pages are still there but the fields are disabled and there is an info text that informs you that creation/edit is not supported with this provider. It looks like the image bellow.
So the question is how do we accomplish this with our custom providers?
In the end the solution was straight forward and pretty easy, but hard to find.
Episerver uses a dictionary where it stores the capabilities for providers, and default providers like SqlMembershipProvider and WindowsMembershipProvider are added by default. The key for the dictionary is the provider Type (Episerver 6).
Methods for adding new entries are public so all we needed to was add the following code to Global.asax.cs.
protected void Application_Start(object sender, EventArgs e)
{
RegisterCapabilitiesOnMembershipProviders();
}
private static void RegisterCapabilitiesOnMembershipProviders()
{
ProviderCapabilities.AddProvider(typeof(CustomActiveDirectoryMembershipProvider), new ProviderCapabilitySettings(0,new string[0]));
ProviderCapabilities.AddProvider(typeof(CustomActiveDirectoryRoleProvider), new ProviderCapabilitySettings(0, new string[0]));
}
This adds our custom membership and role providers to dictionary with no capabilities, meaning that all the create/edit of users and roles are disabled.
The following actions are available: Update, Create, Delete. If you only want Update and Create you replace the 0 with this:
ProviderCapabilities.Action.Update | ProviderCapabilities.Action.Create
The Action enum have the attribute Flags.