More in this section

Forums / Developing with Sitefinity / CustomRoleProvider Form

CustomRoleProvider Form

5 posts, 1 answered
  1. Dave
    Dave avatar
    37 posts
    Registered:
    26 Dec 2008
    27 Feb 2010
    Link to this post
    Hello!

    For a custom role provider I have to extend the forms for editing the role in backend as well. Is this possible, or do I have to write a complete custom backend module?

    If it's possible to extend the existing form, how can I realize that?

    Thanks in advance.

    Dieter
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    28 Feb 2010
    Link to this post
    Hi Dieter,

    The logic of backend roles management is represented by ManageUsers control declared under Sitefinity/Admin/CmsAdmin/Users.aspx. The control has several modes that are used depending on what you are trying to modify. In your case the control uses its RolesTemplate. There are three options

    1. Create a custom control that inherits from ManageUsers class. Override CreateChildControls and implement your custom logic for roles view.

    sample code

    protected override void CreateChildControls()
           {
               this.Controls.Clear();
     
               if (Page != null)
               {
                   if (!Page.IsPostBack)
                   {
                       string name = Page.Request.QueryString["name"];
     
                       if (!string.IsNullOrEmpty(name))
                       {
                           this.username = name;
                           this.Mode = Modes.Edit;
                       }
                   }
               }
               // CREATE CUSTOM DATA SOURCE
               this.dataSource = new UsersDataSource();
               this.dataSource.ID = "UsersDataSource1";
               this.dataSource.Selecting += new CancelEventHandler(dataSource_Selecting);
               this.dataSource.Selected += new UsersDataSourceStatusEventHandler(dataSource_Selected);
     
               switch (this.mode)
               {
                   case Modes.List:
                       base.CreateListView();
                       break;
                   case Modes.Insert:
                   case Modes.Edit:
                       base.CreateEditView();
                       break;
                   case Modes.Roles:
                       this.CreateCustomRolesView();
                       break;
               }
           }
     
     
    private void CreateCustomolesView()
           {
              ...
                  ....
               //IMPLEMENT YOUR CUSTOM DATASOURCE AND BIND THE GRID CONTROL
               RolesDataSource dataSource = new RolesDataSource();
                 ....
                   .....
               this.rolesCnt.Controls.Add(dataSource);
     
               GridView grid = this.rolesCnt.Grid;
               if (grid != null)
               {
                   grid.DataKeyNames = new string[] { "Name" };
                   grid.DataSourceID = dataSource.ID;
                   grid.SelectedIndexChanged += new EventHandler(rolesGrid_SelectedIndexChanged);
                   grid.RowDeleted += new GridViewDeletedEventHandler(grid_RowDeletedRoles);
                   grid.RowDataBound += new GridViewRowEventHandler(grid_RowDataBound);
                  
               }
               this.Controls.Add(this.rolesCnt);
           }

    2. You could try accessing some of the grid items from the code behind of the aspx if this will work for you.

    3. Create a custom control that uses your RoleProvider

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Dave
    Dave avatar
    37 posts
    Registered:
    26 Dec 2008
    04 Mar 2010
    Link to this post
    Hi Ivan!

    Thanks for Your answer.

    I'm trying to realize Your first option. Unfortunatelly I'm getting a NullReferenceException form the method DisplayAll() in ManageUsers. It is possible to send me the code from ManageUsers-Class to find the problem?

    Nice greetings!

    Dieter
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Mar 2010
    Link to this post
    Hello Dieter,

    Here is the method

    public void DisplayAll()
    {
        this.roleName = null;
        this.EnsureGridView();
        this.dataSource.FilterType = UsersFilterType.All;
        this.listCnt.SetGridTitle("All Users");
        BindUsers();
    }

    You can use Reflector if necessary.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  5. Dave
    Dave avatar
    37 posts
    Registered:
    26 Dec 2008
    04 Mar 2010
    Link to this post
    Hi Ivan!

    Thanks, that helped me a lot.

    Nice greetings.

    Dieter
Register for webinar
5 posts, 1 answered