mysql - 更改 asp.net 成员(member)中的用户名

标签 mysql asp.net membership

好吧,所以我希望管理员可以选择在 gridview 中更改某人的用户名,就像我更改他的电子邮件、评论等一样。 这些是我的代码:

protected void UserAccounts_RowEditing(object sender, GridViewEditEventArgs e)
{
    UserAccounts.EditIndex = e.NewEditIndex;
    BindUserAccounts();
}
protected void UserAccounts_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    int index = UserAccounts.EditIndex;
    GridViewRow row = UserAccounts.Rows[e.RowIndex];
    username = UserAccounts.Rows[e.RowIndex].Cells[1].Text;
    email = ((TextBox)row.Cells[2].Controls[0]).Text;
    approvedchange = ((CheckBox)row.Cells[3].Controls[0]).Checked;
    comment = ((TextBox)row.Cells[6].Controls[0]).Text;
    MembershipUser user = Membership.GetUser(username);
    if (user != null)
    {
        bool edited = false;
        ActionStatus.Text = string.Format("<font size=4><b><u>Editing {0}</u></b></font>", username);
        if (!user.Email.Equals(email))
        {
            edited = true;
            user.Email = email;
            ActionStatus.Text += "<br />Email has been successfully updated!";
        }
        if (!user.IsApproved == approvedchange)
        {
            edited = true;
            user.IsApproved = approvedchange;
            ActionStatus.Text += "<br />Approved status has been successfully updated!";
        }
        if (!user.Comment.Equals(comment))
        {
            edited = true;
            user.Comment = comment;
            ActionStatus.Text += "<br />Comment has been successfully updated!";
        }
        if(edited)
            Membership.UpdateUser(user);
        else
            ActionStatus.Text += string.Format("<br />You haven't edited any of {0}'s details, so they haven't been updated!", username);
    }
    else
        ActionStatus.Text += string.Format("ERROR: user == null");
    UserAccounts.EditIndex = -1;
    BindUserAccounts();
}

那么,我该怎么做呢?感谢那些提供帮助的人!

最佳答案

MembershipProvider 不允许更改用户名。

Membership.UpdateUser(user); 仅更新以下信息 -

  • 电子邮件
  • 评论
  • 已批准
  • 上次登录日期

如果您想更改它,您需要在 Membership Provider 之外创建一个函数。

关于mysql - 更改 asp.net 成员(member)中的用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26432115/

相关文章:

c# - 在 HttpModule 中正确使用 ConcurrentQueue?

asp.net - mySQL 获取最高 ID 奇数结果

mysql - 加入两个表的一对多关系,然后将第二个表连接成一个

mysql - 20-30 个并发 mysql 连接导致 RDS 飙升至 80% 以上

mysql - 使用 SELECT 命令加入

javascript - 对动态填充的列表框进行排序

asp.net-mvc-3 - 自定义成员提供程序中的 Unity 依赖注入(inject)

jquery - 在 WordPress 中调用 wp_current_user() 会使非 jquery

iphone - 如何从我的 iOS 开发团队中删除成员?

mysql - 使用 ASP.NET MVC 4 应用程序配置 MySQL