protected void Page_Load(object sender, EventArgs e) { AuthenticationSection authenticationSection = (AuthenticationSection)ConfigurationManager.GetSection("system.web/authentication"); if (authenticationSection.Mode != AuthenticationMode.Forms) { Page.Response.Redirect("~/", true);// this page can only be used with forms authentication. AD authentication assumes user managment happens outside the scope of the web application. } MessageLabel.Text = string.Empty; if (!Page.IsPostBack) { MembershipUserCollection uc = Membership.GetAllUsers(); UserListBox.DataSource = Membership.GetAllUsers(); UserListBox.DataBind(); } }
protected void DeleteUserButton_Click(object sender, EventArgs e) { if (Membership.DeleteUser(UserListBox.SelectedValue, true)) { MessageLabel.Text = string.Format("User '{0}' has been Deleted", UserListBox.SelectedValue); MembershipUserCollection uc = Membership.GetAllUsers(); UserRolesPanel.Visible = false; UserListBox.SelectedIndex = -1; UserListBox.DataSource = Membership.GetAllUsers(); UserListBox.DataBind(); } else { MessageLabel.Text = "Failed to delete user!"; } }