using System; using System.Collections.Generic; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; public partial class RemoveUserAccount : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { currTimeStampLabel.Text = "Today is " + Utilities.GetFormattedDateTime(); if (!Page.IsPostBack) { // Get Windows ID of user string logonUserName = Utilities.GetLoggedInUserID(User.Identity.Name); lblHeader.Text = "You are logged in as " + logonUserName; // Just to be safe, check if user exists MembershipUser user = Membership.GetUser(logonUserName); if (user != null) { if (Roles.IsUserInRole(logonUserName, "AdminPlanning")) { SqlDataSource ds = new SqlDataSource(); ds.ConnectionString = ConfigurationManager.ConnectionStrings["cnSqlRoleManager"].ToString(); ds.DataSourceMode = SqlDataSourceMode.DataSet; // Display form to collect email address collectEmailDiv.Style["display"] = "block"; userNameTextBox.Focus(); } else { // Their account exists but not in role "AdminPlanning", so redirect to homepage Response.Redirect("Default.html", true); } } else { // Their account doesn't exists, so redirect to homepage Response.Redirect("Default.html", true); } } } protected void submitButton_Click(object sender, EventArgs e) { // Get new Windows ID of user to create string logonUserName = userNameTextBox.Text; // Just to be safe, check if user exists again MembershipUser user = Membership.GetUser(logonUserName); if (user != null) { bool success = Membership.DeleteUser(logonUserName); //int success = SqlDataHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["cnSqlRoleManager"].ToString(), "RemovePPSUser", logonUserName); displayMessageLabel.Text = "Account " + logonUserName + " was "; if (success) { displayMessageLabel.Text += "deleted."; } else { displayMessageLabel.Text += "NOT deleted."; } } else { displayMessageLabel.Text = "Account " + logonUserName + " does not exist."; } } }