+1-888-365-2779
Try Now
More in this section

Forums / Security / Problem with CustomMembershipProvider

Problem with CustomMembershipProvider

5 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    03 Feb 2010
    Link to this post
    Hi all,

    I've some troubles with setting up my custom membership provider in Sitefinity.
    I included my custom provider in my SF project. I set up my web.config and after that logged on to SF.

    If I go to the 'Users' section inside the admin tool and choose my custom provider, there are no users showing up.
    When I go to 'Manage Roles' and choose my custom provider, then the roles are showing, so that one works.

    It seems to work because, when starting the ASP.NET Configuration Tool, the users and roles are showing up and I can create and edit the users and roles.

    I'm now busy debugging the function GetAllUsers() inside my custom membership provider:

    public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)

    This function returns no users when 'pageIndex' is set to start on '1'. If I set it to start on '0' it returns my 2 test users from the database, just as the ASP.NET Configuration Tool is doing. It seems that SF is starting the pages at index 1. Is that right? If so, is it a bug, or is it my code?

    I though I could implement just the Microsoft.NET Provider model in my own class and then it should work...

    Please help!

    Thanks!
    Daniel Plomp
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Feb 2010
    Link to this post
    Hi Daniel,

    We use MembershipUserCollection GetAllUsers(int from, int maxRows, string sortExpr, out int totalRows). The page index is zero based and we do not start counting from one. The default value is zero. The method gets a collection of all users in the database.
    If 8 users were in the database, and the pageIndex value was 1 with a pageSize of 3, the MembershipUserCollection returned would contain the fourth through the sixth users returned. Total rows would be 8.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    03 Feb 2010
    Link to this post
    Jup, that is what I was thinking how it should work. Anyway, when I'm debugging and step into this function, then the pageIndex is '1'. I didn't do anything with the code, but when I do this with the ASP.NET Admin Tool, the pageIndex is '0', so I can't figure out where the difference is?

    -Daniel-
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 Feb 2010
    Link to this post
    Hi Daniel,

    There is  problem in the built in implementation that probably cause the problem you have. We have already fixed the problem, but the fix will be available with the next SP in the beginning of March.
     Meanwhile you can fix the problem by implementing custom  and then your custom membership provider should inherit from this interface.

    using System.Web.Security;
    using Telerik.Framework.Security;
      
    public class MyMembershipProvider : SqlMembershipProvider, CustomIExtendedMembershipProvider
    {
        public MembershipUserCollection GetAllUsers(int from, int maxRows, string sortExpr, out int totalRows)
        {
            return base.GetAllUsers(from, maxRows, out totalRows);
        }
      
        public MembershipUserCollection FindUsersByName(string usernameToMatch, int from, int maxRows, string sortExpr, out int totalRows)
        {
            return base.FindUsersByName(usernameToMatch, from, maxRows, out totalRows);
        }
      
        public MembershipUserCollection FindUsersByEmail(string emailToMatch, int from, int maxRows, string sortExpr, out int totalRows)
        {
            return base.FindUsersByEmail(emailToMatch, from, maxRows, out totalRows);
        }
      
        public MembershipUserCollection GetUsersInRole(string roleName, int from, int maxRows, string sortExpr, out int totalRows)
        {
            // implement a logic for returning users in the specified role
            totalRows = 0;
            return new MembershipUserCollection();
        }
    }

    CustomIEdtendedMembershipProvider


    CustomIEdtendedMembershipProvider : IExtendedMembershipProvider
    {
        MembershipUserCollection GetAllUsers(int from, int maxRows, string sortExpr, ref int totalRows);
        MembershipUserCollection FindUsersByName(string usernameToMatch, int from, int maxRows, string sortExpr, ref int totalRows);
        MembershipUserCollection FindUsersByEmail(string emailToMatch, int from, int maxRows, string sortExpr, ref int totalRows);
        MembershipUserCollection GetUsersInRole(string roleName, int from, int maxRows, string sortExpr, ref int totalRows);
    }



    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    04 Feb 2010
    Link to this post
    Hi Ivan,

    Thanks for letting me know.
    I think I'll have to wait for March, because my custom provider is a separate project and is also beeing used by other websites.

    -Daniel-
Register for webinar
5 posts, 0 answered