Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Anders Hattestad
Dec 27, 2010
(5 votes)

Multiplexing providers

Sometimes you want to use more than one security provider. And that's what the EPiServer multiplex provider can help us. You can add one or more providers in the MultiplexingMembershipProvider section and the same numbers of items in the MultiplexingRoleProvider for the roles.


But if one provider allows search for emails, and another doesn't it throws an error. Bit annoying, but is easy to fix. you can add your own multiplexing provider like this:(only added try catch from the underline code)

Code Snippet
  1. public class MultiplexingMembershipProvider : EPiServer.Security.MultiplexingMembershipProvider
  2. {
  3.     public override string GetUserNameByEmail(string email)
  4.     {
  5.         foreach (MembershipProvider provider in this.Providers)
  6.         {
  7.             try
  8.             {
  9.                 string userNameByEmail = provider.GetUserNameByEmail(email);
  10.                 if (userNameByEmail != null)
  11.                 {
  12.                     this.CurrentUsername = userNameByEmail;
  13.                     return userNameByEmail;
  14.                 }
  15.             }
  16.             catch { }
  17.         }
  18.         return null;
  19.     }
  20. }

But there are also times when you want to have 2 user providers and only one role provider. When you have made a page based user provider, and want them to share the same roles. Then its a bit hassle, since if you add 2 of the same role providers, all roles are duplicated.

<add name="MultiplexingRoleProvider" type="Itera.Security.MultiplexingRoleProvider, Itera.Security" 

The trick is to create your own MultiplexingRoleProvider. At the first glance it is pretty straight forward, but there are stuff inside the AdminGroup page that detects if your role provider inherits form MultiplexingRoleProvider, and gets all the users from the Providers from the role provider. And that is not virtual and is not possible to override.image


So to have 2 user providers and only one role provider you have to make your own. And as most of the time you need to copy the code from reflector, and make your modifications.

My modification was that I created a DisitinctProvider list and replaced all references that needed to use that one instead of the Providers.

Code Snippet
  1. public IList<RoleProvider> Providers
  2. {
  3.     get
  4.     {
  5.         if (this._providers == null)
  6.         {
  7.             this.InitProviders();
  8.         }
  9.         return this._providers;
  10.     }
  11. }
  13. public IList<RoleProvider> DistinctProviders
  14. {
  15.     get
  16.     {
  17.         if (this._distinctProviders == null)
  18.         {
  19.             this.InitProviders();
  20.         }
  21.         return this._distinctProviders;
  22.     }
  23. }

The only trouble then is that in the admin group page you don’t get provider behind the role


This is what i would like to call a mistake by the code team that created the AdminGroup page. They should have checked for an interface instead of hardcode in the MultiPlexRoleProvider. or at least made all the properties there virtual.





is inside the zip file here.

Dec 27, 2010


Anders Hattestad
Anders Hattestad Jan 3, 2011 06:37 PM

Not my best blog, but rate it 1 was a bit harse:)

Anders Hattestad
Anders Hattestad Jan 20, 2011 10:12 AM

Wow, got 2 fives :) thx

Dennis Malmgren
Dennis Malmgren Mar 4, 2011 08:33 PM

We ran into this issue with one customer wanting to authenticate against double AD nodes. Unfortunately that was before this post so had to solve it haphazardly :) great 'fix' to the builtin functionality.

Please login to comment.
Latest blogs
New Series: Building a .NET Core headless site on Optimizely Graph and SaaS CMS

Welcome to this new multi-post series where you can follow along as I indulge in yet another crazy experiment: Can we make our beloved Alloy site r...

Allan Thraen | Jun 14, 2024 | Syndicated blog

Inspect In Index is finally back

EPiCode.InspectInIndex was released 9 years ago . The Search and Navigation addon is now finally upgraded to support Optimizely CMS 12....

Haakon Peder Haugsten | Jun 14, 2024

Change the IP HTTP Header used for geo-lookup in Application Insights


Johan Kronberg | Jun 10, 2024 | Syndicated blog

Copying property values

In this article I’d like to show simple Edit Mode extension for copying property values to other language versions. In one of my previous blogposts...

Grzegorz Wiecheć | Jun 8, 2024 | Syndicated blog

Auto-translate with OpenAI GPT-4o in Optimizely CMS

Improvements for Episerver.Labs.LanguageManager! It's now possible to auto-translate both a page and its children at the same time! Additionally, m...

Tomas Hensrud Gulla | Jun 7, 2024 | Syndicated blog

Upgrade To Optimizely CMS 12 Issue: List item fields have become Required

There are many funny details to be aware of when upgrading from Episerver CMS 11 to Optimizely CMS 12. One of them that might feel a bit confusing ...

Allan Thraen | Jun 7, 2024 | Syndicated blog