Add user to role on membership request

Mar 2, 2014 at 5:35 PM
I'm trying to determine where I would add the following line Utils.BaseRoleProvider().AddUsersToRoles(new string[] {user.UserName}, new string[] {"theRole"});
so that when the membership request is filled out(it's locked down to site admins and above only) the user would be added to the role automatically. Any pointers in the right direction would be greatly appreciated.

Thanks
Brian
Coordinator
Mar 3, 2014 at 2:21 AM
If you use SharePoint groups instead of roles (just uncheck 'Enable Roles' in the FBA Site Configuration page) - you can pick a sharepoint group to add the user to automatically right in the web part properties. Being able to select a role in the webpart is added in the next version - but unfortunately I haven't had a chance to complete it yet.

If you want to add the role manually in the code, you'll do it in membershiprequest.cs - ApproveMembership()
Mar 11, 2014 at 2:51 PM
Edited Mar 11, 2014 at 4:45 PM
Thank you much for the reply. That pointed me in the right direction and I was able to get it working by attaching the debugger to the wp3 process. I still need to capture the role the user selects on the membership request form. The radio buttons have been added to the form but I'm still digging around to see where I can capture the selection.

Edit: Got it accepting the user input for the new radio buttons by adding following in the appropriate places in membershiprequestcontrol.cs:
/////////////////////////////////////////////////////////////Code block 1
    private RadioButtonList _txtsiteRoleSelection;
    protected RadioButtonList txtsiteRoleSelection
    {
        get
        {
            if (_txtsiteRoleSelection == null)
            {
                _txtsiteRoleSelection = (RadioButtonList)this.CreateUserStep.ContentTemplateContainer.FindControl("siteRoleSelection");
            }
            return _txtsiteRoleSelection;
        }
    }
///////////////////////////////////////////Code block 2
    public string siteRoleSelection
    {
        get { return txtsiteRoleSelection.SelectedValue; }
        set { txtsiteRoleSelection.Text = value; }
    }
/////////////////////////////////////////////////////////Code 3
request.siteRoleSelection = this.siteRoleSelection;

Thanks for the great application add on and support on the discussion boards!
Hopefully what I posted will help someone else out.

Brian