Copied to clipboard

Flag this post as spam?

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

  • Bart 4 posts 104 karma points
    Jan 11, 2016 @ 19:54

    Custom membership provider

    I've written my own custom membership provider. This custom membership provider inherits System.Web.Security.MembershipProvider. When I try to inherit from Umbraco.Web.Security.Providers.MembersMembershipProvider my implementation is not loaded as my custom members are not visible, only de umbraco members are visible. But this is not the biggest problem. When I see my custom members and want to assign them to a membergroup I get an error System.Data.SqlClient.SqlException: Incorrect syntax near ')'.

    It turns out this is caused by the query: SELECT [text],[Member],[MemberGroup] FROM [umbracoNode] INNER JOIN [cmsMember2MemberGroup] ON [umbracoNode].[id] = [cmsMember2MemberGroup].[MemberGroup] WHERE ([umbracoNode].[nodeObjectType] = '366e63b9-880f-4e13-a61c-98069b029728') AND (cmsMember2MemberGroup.Member in ())

    How can I solve this and use the membergroup editor in Umbraco?

  • Bart 4 posts 104 karma points
    Jan 13, 2016 @ 16:25

    I've found the cause of the problem. The standard UmbracoRoleProvider wants to retrieve the nodeId of the user that needs to be updated. The provider checks the cmsMember tabel to find this user. Evidently the user is not found as a custom membership provider is used where members are not stored in the cmsMembers table.

    I "solved" this by a workaround to sync members of my custom membership provider with the default umbraco membership provider. I choose to create the user in the umbraco membership provider just before the role is assigned. (It might be better to sync all users in application startup.)

    This is the code for the workaround:

        public class CustomMembershipProvider : MembershipProvider { 
        private MembersMembershipProvider _umbracoMembershipProvider;
        public CustomMembershipProvider()
            _umbracoMembershipProvider = new MembersMembershipProvider();
        public override void Initialize(string name, NameValueCollection config)
            if (config == null) { throw new ArgumentNullException("config"); }
            _umbracoMembershipProvider.Initialize(name, config);
            if (string.IsNullOrEmpty(name)) { name = "CustomMemberShipProvider"; }
            base.Initialize(name, config);
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
            var user = GetAllCustomMembershipUsers.FirstOrDefault(u => u.ProviderUserKey!=null && u.ProviderUserKey.Equals(providerUserKey));
            if (user == null) return null;
            var umbracoUser = _umbracoMembershipProvider.GetUser(user.UserName, userIsOnline);
            if (umbracoUser != null) return user;
            MembershipCreateStatus createStatus;
            _umbracoMembershipProvider.CreateUser(user.UserName, Guid.NewGuid().ToString(), user.Email, string.Empty, string.Empty, false, Guid.NewGuid(), out createStatus);
            return user;
        private List<MembershipUser> GetAllCustomMembershipUsers() {
            //Get all users;
Please Sign in or register to post replies

Write your reply to: