与“System.Web.Security.Roles.AddUsersToRole(string[], string)”最匹配的重载方法具有一些无效参数

来源:互联网 发布:水合硅石 知乎 编辑:程序博客网 时间:2024/05/17 02:43

MembershipUser userObj = Membership.CreateUser(user, pswd, email, question, answer, true, out status);
            if (userObj != null)
            {
                Roles.AddUsersToRole(userObj.UserName, role);
             
                messageLabel1.Text = "创建用户成功";
                usernameTextBox.Text = "";
                passwordTextBox.Text = "";
                EmailTextBox1.Text = "";
                securityquestionTextBox.Text = "";
                securityanswerTextBox.Text = "";

            }
错误 3 与“System.Web.Security.Roles.AddUsersToRole(string[], string)”最匹配的重载方法具有一些无效参数
错误 4 参数“1”: 无法从“string”转换为“string[]”

========

此种错误是因为AddUsersToRole用错了,这是将一个用户组加入角色中,AddUserToRole是将一个用户加入角色中。所以这里string[],是个数组,但用的时候是单个用户名。