Skip wrote:vavkin wrote:On the page default.aspx?g=admin_edituser&u=<User number> user roles cannot be saved. In the file edituser.ascx.cs instead of the line
Roles.AddUserToRole(User.UserName, roleName)
you should type in
Roles.AddUserToRole(Name.Text, roleName)
As it's necessary to save the roles of the editable user not the current user
Hello.
I am having problems with the User in usergroups.
No matter what group I assigne the user to, when the user logson he or she has no acces to any forum, and in the admin user page the chckbox for the group the user is assigned to is unchecked.
I was happy to see this bit of code on the forum and thought that it might be the solution to my problem. Alas changing the code in the edituser.ascx.cs didn't work for me.
Anyone have an other idea
Thanx in advance
I haven't seen any posts regarding this issue so I'm assuming that you haven't solved it as of yet. I ran into the same problem and haven't had a lot of time to familiarize myself with the code, but I made the following changes which appear to be working for me.
I first added a new method to the DB.cs class
Code:
static public string group_getStartGroup()
{
using (SqlCommand cmd = new SqlCommand("select name from yaf_group where flags & 4 = 4")) {
cmd.CommandType = CommandType.Text;
string groupName = (string)ExecuteScalar(cmd);
return (groupName != null ? groupName : string.Empty);
}
}
Then I modified the Save_Click method in EditUser.cs, note the
Name.Text change.
Code:
bool isChecked = ((CheckBox)item.FindControl("GroupMember")).Checked;
DB.usergroup_save(Request.QueryString["u"],GroupID,isChecked);
if (isChecked && !Roles.IsUserInRole(Name.Text, roleName))
Roles.AddUserToRole(Name.Text, roleName);
else if (!isChecked && Roles.IsUserInRole(Name.Text, roleName))
Roles.RemoveUserFromRole(Name.Text, roleName);
Finally, I handled the CreatedUser event for the CreateUserWizard1 control (don't forget to hook up this event)
Code:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
string startRole = DB.group_getStartGroup();
startRole = startRole == string.Empty ? "Guest" : startRole;
Roles.AddUserToRole(CreateUserWizard1.UserName, startRole);
}
The cause of this problem (as you may have guessed by the code above) is that the aspnet.UsersInRoles table is not being updated/populated. There are a few other member update problems within the admin interface that are related to the ASP.NET Membership. If these aren't resolved by the time I get a chance to look at them, I'll post what changes I make here.