Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pete 152 posts 176 karma points
    Aug 04, 2010 @ 16:20
    Pete
    0

    Umbraco membership alongside standard asp.net membership?

    Can the two run alongside each other?

    We have two membership types, one of which is already in Umbraco and working. The other I'm trying to avoid putting into the CMS as there a lot of them and they don't need to be managed in the CMS at all (they're pushed from and updated by an outside source)

    Anyone already doing something like this? I.e. running UmbracoMembership alongside asp.net membership? I'd love to know the details.

     

    Cheers!

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Aug 04, 2010 @ 19:21
    Morten Christensen
    2

    Hi Pete,

    Yes, this is indeed possible! I have made such in implementation during the last couple of days and it works great as long as you are aware of which MembershipProvider you are using in your code for Login, Registration and such. If you just use Membership.GetUser(); you will most likely default to your Umbraco Provider, so instead you can do something like Membership.Providers["MyAspNetProvider"].GetUser(userName, isOnline); where MyAspNetProvider is the provider name from your web.config.

    Let me know if you need some more concrete examples.

    - Morten

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 05, 2010 @ 00:51
    Aaron Powell
    2

    I'd actually combine them into a single membership store (preferably the SqlMembership one) rather than having two. And you can change the web.config to use just the asp.net one from within Umbraco itself. It'd make management simpler of the member base as a whole too.

    But no, there isn't a reason why you can't have multiple membership providers configured, and you can access the different ones as Morten has shown.

    The standard ASP.NET UserControl's might need some configuration through.

  • Pete 152 posts 176 karma points
    Aug 05, 2010 @ 10:08
    Pete
    0

    Thanks for the replies, guys. 

    Am I right in assuming that everything will have to be done programmatically and we'd lose the easy drag and drop functionality of all the login controls? 

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Aug 05, 2010 @ 10:44
    Michael Latouche
    0

    Hi Pete,

    The login controls have a "MembershipProvider" property where you can specify the name of the membership provider to use. So, even if you want to use a separate membership provider for your controls, it should not be that different to implement than if you use the "default" provider.

    Cheers!

    Michael.

  • Pete 152 posts 176 karma points
    Aug 05, 2010 @ 10:53
    Pete
    0

    Great stuff, thanks. 

    As I understand it, the UmbracoMembership classes have replaced the SqlMembership classes - is this correct or will just pointing the controls at the correct provider work straight away?

     

    Cheers!

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Aug 05, 2010 @ 11:11
    Michael Latouche
    0

    Hi Pete,

    UmbracoMembership is indeed the default settings, but it can live side-by-side with the SqlMembership.
    If you define a separate provider "MyMembershipProvider" in your web.config and you configure it to use the SqlMembership classes, then the only thing you need to do in your controls is fill in the MembershipProvider property with "MyMembershipProvider". And they will then link straight to the" asp_net SQL" version of the provider.

    Hope this makes sense :-)

    Cheers!

  • Pete 152 posts 176 karma points
    Aug 11, 2010 @ 18:32
    Pete
    0

    A quick follow-up question... 

    How do you then identify which Provider the member has logged in as? I.e. HttpContext.Current.User.Identity.Name only returns the username, which for us is not unique between the two providers (and can't be due to the data provided). 

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Aug 11, 2010 @ 23:31
    Michael Latouche
    0

    Hi Pete,

    I have never come to that situation, but logically, this would have to be the Provider you specified when programming the user login, either via the ASP.Net login control (MembershipProvider property), either via custom code.
    Normally, at some point in the logon procedure, you will have to specify which provider to log in to, and this is the one that is then used throughout the site.

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Aug 12, 2010 @ 11:10
    Michael Latouche
    0

    Hi again Pete,

    If you need to identify the Provider from user name anyway, I guess what you can do is loop through the available Membership Providers and check which one returns you a user mapping the HttpContext.Current.User.Identity.Name.

    So, something like this (.Net 3.5):

    var myProvider = Membership.Providers.OfType<MembershipProvider>().FirstOrDefault(x => x.GetUser(HttpContext.Current.User.Identity.Name, true) != null);

    This would return the first (and unique in your case) Provider which actually returns a MembershipUser when you look for it by username, or null if no matching provider is found.
    I haven't tested the Linq query so it might not work right away (you might actually need to use a for-loop on this), but at least it gives you an idea of the way to go.

    Cheers!

  • Pete 152 posts 176 karma points
    Aug 12, 2010 @ 11:13
    Pete
    0

    Hi guys,

     

    Cheers for the replies. The problem is that the usernames are not unique between the two providers, hence needing a way outside of Identity.Name to identify which part of the site the user logged into. (It's a fairly odd requirement which I hope will eventually be refined)

    We have gotten around it by placing a prefix on the username in code. 

     

    Cheers!

Please Sign in or register to post replies

Write your reply to:

Draft