簡體   English   中英

更改asp.net成員資格的用戶名

[英]Changing usernames in 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(用戶); 僅更新以下信息-

  • 電子郵件
  • 評論
  • 被批准
  • LastLoginDate

如果要更改它,則需要在Membership Provider之外創建一個函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM