using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class CreateAccount : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { currTimeStampLabel.Text = "Today is " + Utilities.GetFormattedDateTime(); lblHeader.Text = "You are logged in as " + Utilities.GetLoggedInUserID(User.Identity.Name); // Get Windows ID of user string logonUserName = Utilities.GetLoggedInUserID(User.Identity.Name); // Just to be safe, check if user exists again MembershipUser user = Membership.GetUser(logonUserName); if (!Page.IsPostBack) { if (user == null) { // Display form to collect email address collectEmailDiv.Style["display"] = "block"; messageDiv.Style["display"] = "none"; } else { // Their accout exists, so try redirecting to homepage Response.Redirect("Default.html", true); } } } protected void submitButton_Click(object sender, EventArgs e) { // Get Windows ID of user string logonUserName = Utilities.GetLoggedInUserID(User.Identity.Name); // Just to be safe, check if user exists again MembershipUser user = Membership.GetUser(logonUserName); if (user == null) { MembershipCreateStatus status; //Use usename1! for the password; not going to be a problem because they don't use it user = Membership.CreateUser(logonUserName, logonUserName + "1!", emailAddress1TextBox.Text, "q", "a", true, out status); //If the status is not a success, as set by the reference variable if (status != MembershipCreateStatus.Success) throw new Exception("The creation failed due to the following status: " + status.ToString()); //Add user to the generic role Roles.AddUserToRole(logonUserName, "WaitingRoleAssignment"); // Display message that request was received collectEmailDiv.Style["display"] = "none"; messageDiv.Style["display"] = "block"; } else { // Their accout exists, so try redirecting to homepage Response.Redirect("Default.html", true); } } }