More in this section

Forums / Developing with Sitefinity / Using a custom membership provider

Using a custom membership provider

13 posts, 0 answered
  1. Ross Reichardt
    Ross Reichardt avatar
    31 posts
    Registered:
    14 Aug 2009
    23 Dec 2009
    Link to this post
    Hi team!
    I am trying to use a custom membership provider which inherits the SQLMembershipProvider class. I am happy to use the Sitefinity role provider. To setup the membership provider I have modified the web.config membership section as follows:

    <membership defaultProvider="Sitefinity" userIsOnlineTimeWindow="15">
        <providers>
            <clear/>
            <add name="Sitefinity" type="TData.Web.Security.TDataSqlMembershipProvider, TData.Web, Version=1.2.0.0" connectionStringName="TDataAspNetDataConnectionString" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Clear" maxPasswordAge="60" numRecentlyUsedPasswords="3" />
        </providers>
    </membership>

    I can log onto the sitefinity front end site and the back end site using my custom membership provider but when I try to administer users, there are no users listed. I can add a user and it does get added into the database but I just can't administer existing users.

    Do you know what I need to do to get my users listed?

    Merry christmas and regards,
    Ross.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    23 Dec 2009
    Link to this post
    Hi Ross Reichardt,

    Thank you for using our services.

    This sound like the sql provider you have added is using a different application name than the one that your currently added users are using. Can you, please verify that the application name property matches the one on your previously existing users?
    <membership defaultProvider="Sitefinity" userIsOnlineTimeWindow="15">
        <providers>
            <clear/>
            <add name="Sitefinity" type="TData.Web.Security.TDataSqlMembershipProvider, TData.Web, Version=1.2.0.0" connectionStringName="TDataAspNetDataConnectionString" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Clear" maxPasswordAge="60" numRecentlyUsedPasswords="3" />
        </providers>
    </membership>

    I hope this helps. If more issues arise, please feel free to get back to us.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Ross Reichardt
    Ross Reichardt avatar
    31 posts
    Registered:
    14 Aug 2009
    23 Dec 2009
    Link to this post

    Hello Radoslav.

    Thanks for your reply. I have tested my MembershipProvider using the applicationName specified in my web.config and it does work. ie the GetAllUsers method does return all the users. Also, I can log on to Sitefinity and I don't think that would be possible if the applicationName was incorrect.

    However, using the same applicationName in Sitefinity still does not return any users in the User Administration page even though I can log on. There is something I am missing here but I don't know what it is. Where else should I look?

    Thanks and regards,

    Ross.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Dec 2009
    Link to this post
    Hello Ross Reichardt,

    Can you paste using the FormatCodeBlock feature of RadEditor)or attach the web.config you use. There could be something wrong in configuration level.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Ross Reichardt
    Ross Reichardt avatar
    31 posts
    Registered:
    14 Aug 2009
    02 Jan 2010
    Link to this post
    Hi Ivan.
    Thanks for your help. Here it is again using the format code block:

          <membership defaultProvider="Sitefinity" userIsOnlineTimeWindow="15"
              <providers> 
                  <clear/> 
                  <!--add name="Sitefinity" type="TData.Web.Security.TDataSqlMembershipProvider, TData.Web, Version=1.2.0.0" connectionStringName="TDataAspNetDataConnectionString" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Clear" maxPasswordAge="60" numRecentlyUsedPasswords="3" /--> 
                  <add name="Sitefinity" type="TData.Web.Security.TDataSqlMembershipProvider, TData.Web, Version=1.2.0.0" connectionStringName="TDataAspNetDataConnectionString" applicationName="/" /> 
              </providers> 
          </membership> 
     


    Best regards,
    Ross.
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    04 Jan 2010
    Link to this post
    Hi Ross Reichardt,

    Thank you for getting back to us.

    Did you use the applicationName setting and MembershipProvider method to get all users in another application? If yes then it works in the context of the current application - i.e. it returns all users for the current application ("/"). In Sitefinity setting this membership provider like this will return users created in the context of the Sitefinity application (which in your application will be different application name). I hope I am explaining this clearly enough. Since your users are coming from an external application the application name in Sitefinity website web.config should not be "/" as this means the website itself.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Ross Reichardt
    Ross Reichardt avatar
    31 posts
    Registered:
    14 Aug 2009
    05 Jan 2010
    Link to this post
    Thanks Radoslav.

    OK, i have changed the application name to something that I know works. I have a unit test which test the GetAllUsers method of the membership provider. When I use the same application name in that test as I do when I use my membership provider in Sitefinity, the test returns all the users. However, in the Sitefinity user admin page, no users are listed at all.

    The odd thing is, when using my membership provider, I can add a user, reset the password and log on but I cannot list all the users or assign them to roles. So, it seems to be half working.

    Thanks and regards,
    Ross.
  8. Joe
    Joe avatar
    6 posts
    Registered:
    04 May 2009
    05 Jan 2010
    Link to this post
    Hi,

    I have a similar problem as the poster.  However, I tried your suggestions and still am having problems.  Here is the error I am getting.
     The method or operation is not implemented. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
     
    Exception Details: System.NotImplementedException: The method or operation is not implemented. 
     
    Source Error: 
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
     
    Stack Trace: 
     
    [NotImplementedException: The method or operation is not implemented.] 
       NopSolutions.NopCommerce.BusinessLogic.Profile.StoreRoleProvider.GetAllRoles() in F:\Own\NopCommerce\Solution\Solution\Libraries\Nop.BusinessLogic\Profile\StoreRoleProvider.cs:86 
       Telerik.Security.UserManager.GetAllRoles() +27 
       Telerik.Security.UserManager.GetRoles() +17 
       Telerik.Security.WebControls.RolesDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +18 
       System.Web.UI.WebControls.Repeater.GetData() +37 
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +214 
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51 
       System.Web.UI.WebControls.Repeater.DataBind() +75 
       Telerik.Security.WebControls.UsersCommands.Refresh() +54 
       Telerik.Security.WebControls.ManageUsers.BindRoles() +72 
       Telerik.Security.WebControls.ManageUsers.SetProvider(String providerName) +102 
       Telerik.Security.WebControls.ManageUsers.commandPanel_ProviderChanged(Object source, ProviderChangedEventArgs e) +45 
       Telerik.Security.WebControls.UsersCommands.OnProviderChanged(ProviderChangedEventArgs e) +97 
       Telerik.Security.WebControls.UsersCommands.ProvidersList_SelectedIndexChanged(Object sender, EventArgs e) +79 
       System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +107 
       System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +134 
       System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +10 
       System.Web.UI.Page.RaiseChangedEvents() +165 
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3135 
     
     
    Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016  
    What I am trying to do is combine nopCommerce into a more sitefinity friendly version (I can provide more details if needed).  My first step is in using multiple membership providers.  I have my web.config file, but I couldn't attach it or use code box because your site timed out (too big) and doesn't allow .txt files.  Let me know your initial thoughts and I will try and add my web.config file seperately.

    Thanks for your help.  Joe
  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Jan 2010
    Link to this post
    Hello Joe,

    Thank you for joining the discussion.

    From the stack trace that you have posted I can see that the error you are getting is because you are calling a method which is not implemented and has throw NotImplementedException(). The stack trace says the error is coming from here:
    NopSolutions.NopCommerce.BusinessLogic.Profile.StoreRoleProvider.GetAllRoles() in F:\Own\NopCommerce\Solution\Solution\Libraries\Nop.BusinessLogic\Profile\StoreRoleProvider.cs:86

    I do not believe this error is related to the same problem Ross is experiencing. If you are implementing an interface class you should implement the GetAllRoles() method.

    Now to Ross' issue. I have to say that to further troubleshoot the cause of this we would need to test your membership provider locally. Ross, can you please open a support ticket and send us the code for the membership provider. Then we will plug it in the source of Sitefinity and  debug it. This will help us pinpoint what the issue might be.

    Thank you very much for your cooperation in advance.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Jan 2010
    Link to this post
    Hi Ross Reichardt,

    This is a follow-up on my previous reply.

    We have played around with creating a custom membership provider, which does not inherit from the Sitefinity one. We have managed to reproduce what you were experiencing. Once we got there we have made our custom membership provider implement the Telerik.Framework.Security.IExtendedMembershipProvider interface. If your membership provider implements this interface the problem will be resolved - this means that you will have to implement the four methods which the interface has. Sample dummy code (note that code will not work unless all interface methods are implemented):
    using System;
    using System.Web.Security;
    using Telerik.Framework.Security;
     
    /// <summary>
    /// Summary description for CustomMembershipProvider
    /// </summary>
    public class CustomMembershipProvider : MembershipProvider, IExtendedMembershipProvider
    {
        #region IExtendedMembershipProvider Members
        public MembershipUserCollection GetAllUsers(int from, int maxRows, string sortExpr, out int totalRows)
        {
            int pageIndex = (int)Math.Ceiling((decimal)from / maxRows);
            return this.GetAllUsers(pageIndex, maxRows, out totalRows);
        }
        public MembershipUserCollection FindUsersByName(string usernameToMatch, int from, int maxRows, string sortExpr, out int totalRows)
        {
            // Ignoring sorting
            int pageIndex = (int)Math.Ceiling((decimal)from / maxRows);
            return this.FindUsersByName(usernameToMatch, pageIndex, maxRows, out totalRows);
        }
        public MembershipUserCollection FindUsersByEmail(string emailToMatch, int from, int maxRows, string sortExpr, out int totalRows)
        {
            // Ignoring sorting
            int pageIndex = (int)Math.Ceiling((decimal)from / maxRows);
            return this.FindUsersByEmail(emailToMatch, pageIndex, maxRows, out totalRows);
        }
        public MembershipUserCollection GetUsersInRole(string roleName, int from, int maxRows, string sortExpr, out int totalRows)
        {
            // Change this according to you RoleProvider setting
            MembershipUserCollection users = new MembershipUserCollection();
            if (Roles.Enabled)
            {
                RoleProvider roles = Roles.Providers[this.Name];
                if (roles == null)
                    roles = Roles.Provider;
                if (roles != null)
                {
                    string[] usernames = roles.GetUsersInRole(roleName);
                    if (users.Count > 1)
                    {
                        int to = maxRows < 0 ? usernames.Length : Math.Min(usernames.Length, from + maxRows);
                        for (int i = from; i < to; i++)
                        {
                            users.Add(this.GetUser(usernames[i], false));
                        }
                    }
                    totalRows = usernames.Length;
                }
            }
            return users;
        }
        #endregion
    }

    Sample implementation of the MembershipProvider Interface can be found here - How to: Sample Membership Provider Implementation.

    Note that we are going to release a SP in the coming couple of weeks. In the new SP custom membership providers will not have to implement the IExtendedMembershipProvider interface.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Ross Reichardt
    Ross Reichardt avatar
    31 posts
    Registered:
    14 Aug 2009
    07 Jan 2010
    Link to this post

    Hi Radoslav.

    Thanks for your help. I followed your suggestion and it works fine except that I can't view users by role. I think that may be because I have not correctly modified your code to suit my role provider. I'll have a look at that and if I can't work out what it wrong I'll get back to you but otherwise I think you have solved it for me.

    Thanks again for the excellent support!

    All the best,

    Ross.

  12. aster
    aster avatar
    12 posts
    Registered:
    08 Dec 2009
    10 Feb 2010
    Link to this post
    Hi

    I have tried implementing the IExtendedMembershipProvider but I still have trouble viewing "All users". When I view the administration section -> users...it just shows a blank page.

    Could you please tell me what else I have to do to get the users to display?

    Thanks
  13. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    11 Feb 2010
    Link to this post
    Hello aster,

    Thank you for jointing the conversation.

    Could you please show us the code for your IExtendedMembership provider? Also when you are using this provider make sure that it is using the correct connection string and is actually pulling data from the database.
     
    Greetings,
    Radoslav Georgiev
    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.
Register for webinar
13 posts, 0 answered