Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Membership provider changes after successful login (multiple membership providers)

Posted on 2010-11-08
Medium Priority
Last Modified: 2012-05-10
Hello All,

I have a site in which I'm intending to use multiple membership providers.  I'm using my own custom membership provider to provide access to several data stores depending on the section in which the user's information resides.

The actual login functions correctly using the built-in ASP.NET Login component in which I've manually specified the membership provider it should validate against.  When I run a trace on it's actions, I can see that it attempts the 'validateuser' against the correct data store and continues to redirect the user to their applicable section.

The problem is that once they are logged in and the site (or I) call 'GetUser' to get the users information or permissions, the membership provider reverts to the site's default provider.

In my custom membership provider I'm only overriding the methods for GetUser and Validate user which is working perfectly fine for a singular membership provider, but not when using a different provider.

How can I ensure that the correct membership provider is retained with the user's membership details?  Is there a method that I need to override/append in order to achieve what I'm looking for?


Question by:Anubis2005
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 20

Assisted Solution

by:Daniel Van Der Werken
Daniel Van Der Werken earned 1000 total points
ID: 34087804
The only way I can think of to do this right off the bat is to have some way to lookup the membership provider to use in the database.

For example, have a table that correlates the member_id with the provider.

So let's say we have:


Member_id Name  Provider
1                    Anubis  0
2                    Daniel 1

Then, the GetUser( string username, bool userIsOnline )
now does this:

providerName = GetProvider( username );

switch (providerName )

case  FirstMembershipProvider:
  provider = new FirstMembershipProvider();

case SecondMembershipProvider:
  provider = new SecondMembershipProvider();

MembershipUser user = provider.GetUser( username );

Or something like that.


Author Comment

ID: 34088010
Hi Dan7el,

Thanks for the reply.  Although this might work, in a case where usernames are the same across multiple providers, it wouldn't work properly.

I've been looking at the methods/steps behind the scenes of how the login component authenticates a user, I'm successfully overriding the 'ValidateUser' part of this, but obviously .NET creates a MembershipUser object for the logged in user at some point.

If I can find at what exact point this is done, I could override it to ensure that my membership user maintains the appropriate provider.

I've been searching for 'behind the scenes' details of the login control's actions but I'm coming up empty.

LVL 41

Assisted Solution

guru_sami earned 1000 total points
ID: 34088454
I don't know to override defaultprovider but you can always select which provider to use like:

Membership.Providers["yourprovidername"].GetUser("someusername", false);
yourprovidername and someusername can be passed via some variable.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 34088664
Hi guru_sami,

Thanks for the reply.

This is ok for when I manually want to call it, but asp.net when redirecting to protected pages it's calling the default provider instead of the correct provider and throws the user out.

I can't seem to find a way to tell asp.net that it should maintain the specified provider.

LVL 41

Expert Comment

ID: 34088693
-->asp.net when redirecting to protected pages it's calling the default provider
I didn't get that part...because once you set forms authentication cookie, it shouldn't matter unless you are talking of roles and roles provider.

Accepted Solution

Anubis2005 earned 0 total points
ID: 34159000
Hi guru_sami,

It matters when in the page you try to call some information about the authenticated user through the 'Membership.????' class.  This uses the default membership provider for the site as a whole.

I've since resolved my issue by writing my own 'Membership' helper class to use instead of the built-in membership class so that I can specify the provider I should be look in.  

I would have thought that .net would have been smart enough to 'remember' that if a user logs in from a specific membership provider, it would us this provider for all membership related calls beyond that point, but alas, it is not.

Thanks for all your help and comments.

Author Closing Comment

ID: 34186435
Solved the issue myself by writing a custom class to handle what I wanted.  Not a perfect solution, but it's working.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question