Copied to clipboard

Flag this post as spam?

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


  • Bex 444 posts 555 karma points
    Jun 09, 2011 @ 16:30
    Bex
    0

    Custom Membership Provider Help!

    Hi!

     

    I am trying to create a custom membership provider for my front end users as theire logins are all stored in an external DB.

    This is not something I've done before, umbraco or otherwise and I am struggling.

    My requirements:

    • Pages can be protected from the backend
    • logged in users have access to all the these pages (I don't care about roles)
    Not too much to ask really?! (then why am I struggling so much?)
    So far I have created a class and inherited from MembershipProvider and because it crashes if I don't I have created a custom role provider.
    I have overriden ValidateUser (I have tested this with the login control and it returns the correct value) and I store a userId and username in a session.
    I have also overriden the GetUser functions, but all I am doing in them is using my stored ID and returning a membershipuser with just a userid and name:
            public override MembershipUser GetUser(object unused, bool userIsOnline)
            {
                if (HttpContext.Current.Session[CurrentUserIdSessionName] != null)
                {
                    MembershipUser user = new MembershipUser(
                        "myProvider",
                         HttpContext.Current.Session[CurrentUserNameSessionName].ToString(),
                        HttpContext.Current.Session[CurrentUserIdSessionName],
                        "",
                        "",
                        "",
                        true,
                        false,
                        DateTime.Now,
                        DateTime.Now,
                        DateTime.Now,
                        DateTime.Now,
                        DateTime.Now);
    
                    return user;
    
    
    
                }
                return null;
            }

    The problem occurs when I try and protect pages.
    As I don't have roles as such I am just setting the page as protected and not assigning a role (maybe this is my problem) but when I log in it accepts my login details returns true then bounces me back to the login again.

    In my role provider I can see it is calling the "GetRolesForUser" function, which I am returning 
     string[] roles =new string[1];
                roles[0] = "user";
                return roles;
    from (I am clutching at straws!) and I returning true for the isUserInRole
     public override bool IsUserInRole(string username, string roleName)
            {
                return true;
            }

    I'm assuming it will just take it as the user is just in the role?

    I know this is very convoluted, but I only want something simple and I'm 99% sure I'm doing it wrong.

    Can someone help?

     

    Bex

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies