/// <summary>
        /// Handles the Click event of the SubmitButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var user = Membership.GetUser(UserName.Text.Trim());
                if (user != null && user.IsApproved)
                {
                    var    profile = new WebProfile().GetProfile(UserName.Text.Trim());
                    string token   = profile.PasswordVerificationToken;

                    // Generate password reset token and store in the users profile
                    if (string.IsNullOrWhiteSpace(token))
                    {
                        token = GenerateToken();
                        profile.PasswordVerificationToken = token;
                        profile.PasswordVerificationTokenExpirationDate = DateTime.Now.AddMinutes(1440);
                        profile.Save();
                    }

                    // Email the user the password reset token
                    UserManager.SendForgotPasswordEmail(user, token);
                }

                forgotPassword.Visible = false;
                successMessage.Visible = true;
            }
        }
        public void BillingEdits(object s, RepeaterCommandEventArgs e)
        {
            Address address = new Address();
              Guid selectedAddress = new Guid(e.CommandArgument.ToString());
              _user = new WebProfile().GetProfile(ddlCustomer.SelectedValue);
              address = _user.AddressCollection.Find(delegate(Address addressToFind) {
            return addressToFind.AddressId == selectedAddress && addressToFind.AddressType == AddressType.BillingAddress;
              });

              if (address.AddressId != Guid.Empty) {
            if (e.CommandName == "Edit") {
              //Do the edit
              pnlBillingAddresses.Visible = false;
              pnlShippingAddresses.Visible = false;
              pnlEditAddress.Visible = true;
              LoadEditPanel(address);
              tcMyAccount.ActiveTab = tpAddresses;
            }
            if (e.CommandName == "Delete") {
              _user.AddressCollection.Remove(address);
              _user.Save();
              LoadAddresses();
              tcMyAccount.ActiveTab = tpAddresses;
            }
              }
        }
Example #3
0
        public void BillingEdits(object s, RepeaterCommandEventArgs e)
        {
            Address address         = new Address();
            Guid    selectedAddress = new Guid(e.CommandArgument.ToString());

            _user   = new WebProfile().GetProfile(ddlCustomer.SelectedValue);
            address = _user.AddressCollection.Find(delegate(Address addressToFind) {
                return(addressToFind.AddressId == selectedAddress && addressToFind.AddressType == AddressType.BillingAddress);
            });

            if (address.AddressId != Guid.Empty)
            {
                if (e.CommandName == "Edit")
                {
                    //Do the edit
                    pnlBillingAddresses.Visible  = false;
                    pnlShippingAddresses.Visible = false;
                    pnlEditAddress.Visible       = true;
                    LoadEditPanel(address);
                    tcMyAccount.ActiveTab = tpAddresses;
                }
                if (e.CommandName == "Delete")
                {
                    _user.AddressCollection.Remove(address);
                    _user.Save();
                    LoadAddresses();
                    tcMyAccount.ActiveTab = tpAddresses;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Handles the Click event of the AddNewUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddNewUserClick(object sender, EventArgs e)
        {
            if (!Page.IsValid) { return; }

            var password = chkRandomPassword.Checked ? Membership.GeneratePassword(7, 0) : Password.Text;

            var createStatus = MembershipCreateStatus.Success;
            string resultMsg;

            var userIdText = UserName.Text;
            var emailText = Email.Text;
            var isActive = ActiveUser.Checked;

            var question = "";
            var answer = "";

            if (Membership.RequiresQuestionAndAnswer)
            {
                question = SecretQuestion.Text;
                answer = SecretAnswer.Text;
            }

            try
            {
                var mu = Membership.RequiresQuestionAndAnswer ?
                    Membership.CreateUser(userIdText, password, emailText, question, answer, isActive, out createStatus) :
                    Membership.CreateUser(userIdText, password, emailText);

                if (createStatus == MembershipCreateStatus.Success && mu != null)
                {
                    var profile = new WebProfile().GetProfile(mu.UserName);
                    profile.DisplayName = DisplayName.Text;
                    profile.FirstName = FirstName.Text;
                    profile.LastName = LastName.Text;
                    profile.Save();

                    //auto assign user to roles
                    var roles = RoleManager.GetAll();
                    foreach (var r in roles.Where(r => r.AutoAssign))
                    {
                        RoleManager.AddUser(mu.UserName, r.Id);
                    }
                }

                ResetForNewUser();

                resultMsg = GetLocalResourceObject("UserCreated").ToString();
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Information;

            }
            catch (Exception ex)
            {
                resultMsg = GetLocalResourceObject("UserCreatedError") + "<br/>" + ex.Message;
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Error;
            }

            MessageContainer.Text = resultMsg;
            MessageContainer.Visible = true;
        }
Example #5
0
        /// <summary>
        /// Handles the Click event of the AddNewUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddNewUserClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var password = chkRandomPassword.Checked ? Membership.GeneratePassword(7, 0) : Password.Text;

            var    createStatus = MembershipCreateStatus.Success;
            string resultMsg;

            var userIdText = UserName.Text;
            var emailText  = Email.Text;
            var isActive   = ActiveUser.Checked;

            try
            {
                var mu = Membership.CreateUser(userIdText, password, emailText);

                if (createStatus == MembershipCreateStatus.Success && mu != null)
                {
                    var profile = new WebProfile().GetProfile(mu.UserName);
                    profile.DisplayName = DisplayName.Text;
                    profile.FirstName   = FirstName.Text;
                    profile.LastName    = LastName.Text;
                    profile.Save();

                    //auto assign user to roles
                    var roles = RoleManager.GetAll();
                    foreach (var r in roles.Where(r => r.AutoAssign))
                    {
                        RoleManager.AddUser(mu.UserName, r.Id);
                    }
                }

                if (!UserCustomFieldManager.SaveCustomFieldValues((Guid)mu.ProviderUserKey, ctlUserCustomFields.Values))
                {
                    throw new Exception(Resources.Exceptions.SaveCustomFieldValuesError);
                }

                ResetForNewUser();

                resultMsg = GetLocalResourceObject("UserCreated").ToString();
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Information;
            }
            catch (Exception ex)
            {
                resultMsg = GetLocalResourceObject("UserCreatedError") + "<br/>" + ex.Message;
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Error;
            }

            MessageContainer.Text    = resultMsg;
            MessageContainer.Visible = true;
        }
Example #6
0
        protected void lbUpdateAddress_Click(object sender, EventArgs e)
        {
            _user           = new WebProfile().GetProfile(ddlCustomer.SelectedValue);
            Address address = _user.AddressCollection.Find(delegate(Address addressToFind) {
                return(addressToFind.AddressId == new Guid(hfAddressId.Value) &&
                       addressToFind.AddressType == (AddressType)Enum.Parse(typeof(AddressType), hfAddressType.Value));
            });

            AddressType addressType = address.AddressType;

            _user.AddressCollection.Remove(address);
            _user.Save();

            address.FirstName     = txtFirstName.Text;
            address.LastName      = txtLastName.Text;
            address.Phone         = txtPhone.Text;
            address.Email         = txtEmailEdit.Text;
            address.Address1      = txtAddress1.Text;
            address.Address2      = txtAddress2.Text;
            address.City          = txtCity.Text;
            address.StateOrRegion = ddlStateOrRegion.SelectedValue;
            address.Country       = ddlCountry.SelectedValue;
            address.PostalCode    = txtPostalCode.Text;
            address.UserName      = WebUtility.GetUserName();
            address.AddressType   = addressType;

            _user.AddressCollection.Add(address);
            _user.Save();

            LoadAddresses();
            pnlEditAddress.Visible       = false;
            pnlBillingAddresses.Visible  = true;
            pnlShippingAddresses.Visible = true;

            tcMyAccount.ActiveTab = tpAddresses;
        }
Example #7
0
        public static void Save(UserInfo profile)
        {
            WebProfile p = WebProfile.GetProfile(profile.UserName);

            p.Age           = profile.Age;
            p.Email         = profile.Email;
            p.Height.Feet   = profile.Height.Feet;
            p.Height.Inches = profile.Height.Inches;
            p.Name          = profile.Name;
            p.Phone         = profile.Phone;
            p.Sex           = profile.Sex;
            p.Preferences   = profile.Preferences;
            p.Weight        = profile.Weight;
            p.Save();
        }
Example #8
0
        /// <summary>
        /// Handles the Click event of the Submit control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Submit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // get the user by the reset token
                var token = Request.QueryString["token"];

                if (!string.IsNullOrWhiteSpace(token))
                {
                    var user = UserManager.GetUserByPasswordResetToken(token);

                    if (user != null)
                    {
                        try
                        {
                            // update the users password to the new password provided
                            user.ChangePassword(user.ResetPassword(), Password.Text.Trim());

                            // update profile to clear the reset token and date
                            var profile = new WebProfile().GetProfile(user.UserName);
                            profile.PasswordVerificationToken = null;
                            profile.PasswordVerificationTokenExpirationDate = null;
                            profile.Save();

                            Response.Redirect("~/Account/PasswordResetSuccess.aspx");
                        }
                        catch (System.Web.Security.MembershipPasswordException ex)
                        {
                            Message         = ex.Message;
                            message.Visible = !String.IsNullOrEmpty(Message);
                        }
                    }
                    else
                    {
                        Message         = GetLocalResourceObject("InvalidTokenMessage").ToString();
                        message.Visible = !String.IsNullOrEmpty(Message);
                    }
                }
                else
                {
                    Message         = GetLocalResourceObject("InvalidTokenMessage").ToString();
                    message.Visible = !String.IsNullOrEmpty(Message);
                }
            }
        }
Example #9
0
    public void SaveProfile()
    {
        // get the selected user's profile
        WebProfile profile = Profile;

        if (username.Length > 0)
        {
            profile = WebProfile.Get(username);
        }

        // Subscriptions
        profile.Preferences.Newsletter = ddlNewsletter.SelectedValue;

        // Personal Info
        profile.Personal.FirstName = txtFirstName.Text;
        profile.Personal.LastName  = txtLastName.Text;
        profile.Personal.Gender    = ddlGenders.SelectedValue;
        if (txtBirthDate.Text.Trim().Length > 0)
        {
            profile.Personal.BirthDate = DateTime.Parse(txtBirthDate.Text);
        }
        profile.Personal.Occupation = ddlOccupations.SelectedValue;
        profile.Personal.Website    = txtWebsite.Text;

        // Address Info
        profile.Address.Country    = ddlCountries.SelectedValue;
        profile.Address.Address    = txtAddress.Text;
        profile.Address.AptNumber  = txtAptNumber.Text;
        profile.Address.City       = txtCity.Text;
        profile.Address.State      = txtState.Text;
        profile.Address.PostalCode = txtPostalCode.Text;

        // Contact Info
        profile.Contacts.DayTimePhone    = txtDayTimePhone.Text;
        profile.Contacts.DayTimePhoneExt = txtDayTimePhoneExt.Text;
        profile.Contacts.EveningPhone    = txtEveningPhone.Text;
        profile.Contacts.EveningPhoneExt = txtEveningPhoneExt.Text;
        profile.Contacts.CellPhone       = txtCellPhone.Text;
        profile.Contacts.FaxBusiness     = txtBusinessFax.Text;
        profile.Contacts.FaxHome         = txtHomeFax.Text;

        // this is what we will call from the button click
        // to save the user's profile
        profile.Save();
    }
Example #10
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }

            var user        = UserManager.GetUser(RegisterUser.UserName);
            var profile     = new WebProfile().GetProfile(user.UserName);
            var displayName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayName");
            var firstName   = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName");
            var lastName    = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName");

            profile.DisplayName = displayName.Text;
            profile.FirstName   = firstName.Text;
            profile.LastName    = lastName.Text;

            profile.Save();

            // add users to all auto assigned roles
            var roles = RoleManager.GetAll();

            foreach (var r in roles.Where(r => r.AutoAssign))
            {
                RoleManager.AddUser(user.UserName, r.Id);
            }

            //send notification this user was created
            UserManager.SendUserRegisteredNotification(user.UserName);

            // send user verification email if enabled
            if (HostSettingManager.Get(HostSettingNames.UserRegistration, (int)UserRegistration.Verified) == (int)UserRegistration.Verified)
            {
                UserManager.SendUserVerificationNotification(user);
            }
            else
            {
                Response.Redirect(continueUrl);
            }
        }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        string UserId = this.txtUserName.Text;
        MembershipUser user = Membership.CreateUser(UserId, UserId, txtEmail.Text);
        if (user != null)
        {
            FormsAuthentication.Authenticate(UserId, UserId);
            WebProfile Profile = new WebProfile();
            Profile.Initialize(UserId, true);
            Profile.FirstName = this.txtFirstName.Text;
            Profile.LastName = this.txtLastName.Text;
            Profile.Newsletter = this.chkNewsLetter.Checked;
            Profile.Email = this.txtEmail.Text;
            Profile.Save();

            GenericIdentity userIdentity = new GenericIdentity(UserId);
            GenericPrincipal userPrincipal =
              new GenericPrincipal(userIdentity, new string[] { "User" });
            Context.User = userPrincipal;

            if (!Roles.IsUserInRole(User.Identity.Name, "User"))
            {
                PAB.Web.Providers.SimpleSqlRoleProvider prov = new SimpleSqlRoleProvider();
                NameValueCollection config = new NameValueCollection();
                config["connectionStringName"] = "OpenId";
                System.Configuration.ConnectionStringSettings ConnectionStringSettings =
                    System.Configuration.ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
                prov.Initialize("", config);
                prov.AddUsersToRoles(new string[] { User.Identity.Name }, new string[] { "User" });
            }
            // go to a page for users who are authenticated
            Response.Redirect("Default2.aspx");
        }
        else
        {
            //uh-oh! you handle it appropriately.
        }

    }
Example #12
0
        /// <summary>
        /// Handles the Click event of the cmdUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void CmdUpdateClick(object sender, EventArgs e)
        {
            try
            {
                GetMembershipData(UserId);

                if (MembershipData != null)
                {
                    var profile = new WebProfile().GetProfile(MembershipData.UserName);
                    profile.DisplayName = DisplayName.Text;
                    profile.FirstName = FirstName.Text;
                    profile.LastName = LastName.Text;
                    profile.Save();

                    ActionMessage.ShowSuccessMessage(GetLocalResourceObject("UpdateProfile").ToString());
                    OnAction(new ActionEventArgs { Trigger = Globals.ActionTriggers.Save });
                }
            }
            catch
            {
                ActionMessage.ShowErrorMessage(LoggingManager.GetErrorMessageResource("ProfileUpdateError"));
            }
        }
Example #13
0
        /// <summary>
        /// Handles the Click event of the AddNewUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddNewUser_Click(object sender, EventArgs e)
        {
            string password;

            //if (chkRandomPassword.Checked)
            //{
            //    cvPassword.Enabled = false;
            //    rvConfirmPassword.Enabled = false;
            //    rvPassword.Enabled = false;
            //    password = Membership.GeneratePassword(7, 0);
            //}
            //else
            //{
            //    rvConfirmPassword.Enabled = true;
            //    rvPassword.Enabled = true;
            //    password = Password.Text;
            //}

            if (!Page.IsValid)
            {
                return;
            }

            if (chkRandomPassword.Checked)
            {
                password = Membership.GeneratePassword(7, 0);
            }
            else
            {
                password = Password.Text;

            }

            MembershipCreateStatus createStatus = MembershipCreateStatus.Success;
            string resultMsg = "";

            string userIDText = UserName.Text;
            string emailText = Email.Text;
            bool isActive = ActiveUser.Checked;

            string question = "";
            string answer = "";
            if (Membership.RequiresQuestionAndAnswer)
            {
                question = SecretQuestion.Text;
                answer = SecretAnswer.Text;
            }

            try
            {
                MembershipUser mu = null;

                if (Membership.RequiresQuestionAndAnswer)
                {
                    mu = Membership.CreateUser(userIDText, password, emailText, question, answer, isActive, out createStatus);
                }
                else
                {
                    mu = Membership.CreateUser(userIDText, password, emailText);
                }

                if (createStatus == MembershipCreateStatus.Success && mu != null)
                {
                    WebProfile Profile = new WebProfile().GetProfile(mu.UserName);
                    Profile.DisplayName = DisplayName.Text;
                    Profile.FirstName = FirstName.Text;
                    Profile.LastName = LastName.Text;
                    Profile.Save();

                    //auto assign user to roles
                    List<Role> roles = RoleManager.GetAll();
                    foreach (Role r in roles)
                    {
                        if (r.AutoAssign)
                            RoleManager.AddUser(mu.UserName, r.Id);
                    }
                }

                ImageButton2.Enabled = false;
                LinkButton2.Enabled = false;

                resultMsg = GetLocalResourceObject("UserCreated").ToString();
                Message1.IconType = BugNET.UserControls.Message.MessageType.Information;

            }
            catch (Exception ex)
            {
                resultMsg = GetLocalResourceObject("UserCreatedError").ToString() + "<br/>" + ex.Message;
                Message1.IconType = BugNET.UserControls.Message.MessageType.Error;
            }

            Message1.Text = resultMsg;
            Message1.Visible = true;
        }
Example #14
0
        /// <summary>
        /// Handles the Click event of the AddNewUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddNewUserClick(object sender, EventArgs e)
        {
            if (!Page.IsValid) { return; }

            var password = chkRandomPassword.Checked ? Membership.GeneratePassword(7, 0) : Password.Text;

            var createStatus = MembershipCreateStatus.Success;
            string resultMsg;

            var userIdText = UserName.Text;
            var emailText = Email.Text;
            var isActive = ActiveUser.Checked;
            
            try
            {
                var mu = Membership.CreateUser(userIdText, password, emailText);

                if (createStatus == MembershipCreateStatus.Success && mu != null)
                {
                    var profile = new WebProfile().GetProfile(mu.UserName);
                    profile.DisplayName = DisplayName.Text;
                    profile.FirstName = FirstName.Text;
                    profile.LastName = LastName.Text;
                    profile.Save();

                    //auto assign user to roles
                    var roles = RoleManager.GetAll();
                    foreach (var r in roles.Where(r => r.AutoAssign))
                    {
                        RoleManager.AddUser(mu.UserName, r.Id);
                    }
                }
                
                if (!UserCustomFieldManager.SaveCustomFieldValues((Guid)mu.ProviderUserKey, ctlUserCustomFields.Values))
                {
                    throw new Exception(Resources.Exceptions.SaveCustomFieldValuesError);
                }

                ResetForNewUser();
  
                resultMsg = GetLocalResourceObject("UserCreated").ToString();
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Information;
                
            }
            catch (Exception ex)
            {
                resultMsg = GetLocalResourceObject("UserCreatedError") + "<br/>" + ex.Message;
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Error;
            }

            MessageContainer.Text = resultMsg;
            MessageContainer.Visible = true;
        }
Example #15
0
        /// <summary>
        /// Installs the BugNET.
        /// </summary>
        /// <returns></returns>
        private bool InstallBugNET()
        {
            try
            {
                var providerPath = UpgradeManager.GetProviderPath();

                if (!providerPath.StartsWith("ERROR"))
                {
                    WriteMessage(string.Format("Installing Version: {0}<br/>", UpgradeManager.GetCurrentVersion()), 0, true);
                    WriteMessage("Installing BugNET Database:<br/>", 0, true);
                    ExecuteSqlInFile(string.Format("{0}BugNET.Schema.SqlDataProvider.sql", providerPath));
                    WriteMessage("Installing BugNET Default Data:<br/>", 0, true);
                    ExecuteSqlInFile(string.Format("{0}BugNET.Data.SqlDataProvider.sql", providerPath));
                    WriteMessage("Creating Administrator Account<br/>", 0, true);

                    //create admin user
                    MembershipCreateStatus status;

                    var newUser = Membership.CreateUser("Admin", "password", "*****@*****.**", "no question", "no answer", true, out status);

                    switch (status)
                    {
                    case MembershipCreateStatus.Success:
                        WriteMessage("Created Administrator Account", 0, true);
                        WriteScriptSuccessError(true);
                        break;

                    case MembershipCreateStatus.InvalidUserName:
                    case MembershipCreateStatus.InvalidPassword:
                    case MembershipCreateStatus.InvalidQuestion:
                    case MembershipCreateStatus.InvalidAnswer:
                    case MembershipCreateStatus.InvalidEmail:
                    case MembershipCreateStatus.DuplicateUserName:
                    case MembershipCreateStatus.DuplicateEmail:
                    case MembershipCreateStatus.UserRejected:
                    case MembershipCreateStatus.InvalidProviderUserKey:
                    case MembershipCreateStatus.DuplicateProviderUserKey:
                    case MembershipCreateStatus.ProviderError:
                        var message = string.Format("Creating Administrator Account Failed, status returned: {0} <br/>", status);
                        WriteMessage(message, 0, true);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    WriteMessage("Creating Administrator Account default profile <br/>", 0, true);

                    if (status == MembershipCreateStatus.Success)
                    {
                        //add the admin user to the Super Users role.
                        RoleManager.AddUser("Admin", 1);

                        //add user profile information
                        var profile = new WebProfile().GetProfile("Admin");
                        profile.FirstName   = "Admin";
                        profile.LastName    = "Admin";
                        profile.DisplayName = "Administrator";
                        profile.PasswordVerificationTokenExpirationDate = null;
                        profile.Save();

                        WriteMessage("Created Administrator Account default profile", 0, true);
                        WriteScriptSuccessError(true);
                    }
                    else
                    {
                        WriteMessage("Created Administrator Account default profile failed, due to status returned from account creation", 0, true);
                        WriteScriptSuccessError(false);
                    }

                    UpgradeManager.UpdateDatabaseVersion(UpgradeManager.GetCurrentVersion());
                }
                else
                {
                    //upgrade error
                    Response.Write("<h2>Upgrade Error: " + providerPath + "</h2>");
                    return(false);
                }
            }
            catch (Exception e)
            {
                WriteErrorMessage(e.Message);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Handles the AuthenticateRequest event of the context control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        void context_AuthenticateRequest(object sender, EventArgs e)
        {
            //check if we are upgrading/installing
            if (HttpContext.Current.Request.Url.LocalPath.ToLower().EndsWith("install.aspx"))
            {
                return;
            }

            //get host settings
            bool enabled = HostSettingManager.Get(HostSettingNames.UserAccountSource) == "ActiveDirectory" || HostSettingManager.Get(HostSettingNames.UserAccountSource) == "WindowsSAM";

            //check if windows authentication is enabled in the host settings
            if (enabled)
            {
                if (System.Web.HttpContext.Current.User != null)
                {
                    MDC.Set("user", System.Web.HttpContext.Current.User.Identity.Name);
                }

                // This was moved from outside "if enabled" to only happen when we need it.
                HttpRequest request = HttpContext.Current.Request;

                // not needed to be removed
                // HttpResponse response = HttpContext.Current.Response;

                if (request.IsAuthenticated)
                {
                    if ((HttpContext.Current.User.Identity.AuthenticationType == "NTLM" || HttpContext.Current.User.Identity.AuthenticationType == "Negotiate"))
                    {
                        //check if the user exists in the database
                        MembershipUser user = UserManager.GetUser(HttpContext.Current.User.Identity.Name);

                        if (user == null)
                        {
                            try
                            {
                                UserProperties         userprop     = GetUserProperties(HttpContext.Current.User.Identity.Name);
                                MembershipUser         mu           = null;
                                MembershipCreateStatus createStatus = MembershipCreateStatus.Success;

                                //create a new user with the current identity and a random password.
                                if (Membership.RequiresQuestionAndAnswer)
                                {
                                    mu = Membership.CreateUser(HttpContext.Current.User.Identity.Name, Membership.GeneratePassword(7, 2), userprop.Email, "WindowsAuth", "WindowsAuth", true, out createStatus);
                                }
                                else
                                {
                                    mu = Membership.CreateUser(HttpContext.Current.User.Identity.Name, Membership.GeneratePassword(7, 2), userprop.Email);
                                }

                                if (createStatus == MembershipCreateStatus.Success && mu != null)
                                {
                                    WebProfile Profile = new WebProfile().GetProfile(HttpContext.Current.User.Identity.Name);
                                    if (!string.IsNullOrWhiteSpace(userprop.DisplayName))
                                    {
                                        Profile.DisplayName = userprop.DisplayName;
                                    }
                                    else
                                    {
                                        Profile.DisplayName = String.Format("{0} {1}", userprop.FirstName, userprop.LastName);
                                    }
                                    Profile.FirstName = userprop.FirstName;
                                    Profile.LastName  = userprop.LastName;
                                    Profile.Save();

                                    //auto assign user to roles
                                    List <Role> roles = RoleManager.GetAll().FindAll(r => r.AutoAssign == true);
                                    foreach (Role r in roles)
                                    {
                                        RoleManager.AddUser(mu.UserName, r.Id);
                                    }
                                }

                                user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                            }
                            catch (Exception ex)
                            {
                                if (Log.IsErrorEnabled)
                                {
                                    Log.Error(String.Format("Unable to add new user '{0}' to BugNET application. Authentication Type='{1}'.", HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.AuthenticationType), ex);
                                }
                            }
                        }
                        else
                        {
                            //update the user's last login date.
                            user.LastLoginDate = DateTime.Now;
                            Membership.UpdateUser(user);
                        }
                    }
                }
            }
        }
        protected void lbUpdateAddress_Click(object sender, EventArgs e)
        {
            _user = new WebProfile().GetProfile(ddlCustomer.SelectedValue);
              Address address = _user.AddressCollection.Find(delegate(Address addressToFind) {
            return addressToFind.AddressId == new Guid(hfAddressId.Value) &&
               addressToFind.AddressType == (AddressType)Enum.Parse(typeof(AddressType), hfAddressType.Value);
              });

              AddressType addressType = address.AddressType;
              _user.AddressCollection.Remove(address);
              _user.Save();

              address.FirstName = txtFirstName.Text;
              address.LastName = txtLastName.Text;
              address.Phone = txtPhone.Text;
              address.Email = txtEmailEdit.Text;
              address.Address1 = txtAddress1.Text;
              address.Address2 = txtAddress2.Text;
              address.City = txtCity.Text;
              address.StateOrRegion = ddlStateOrRegion.SelectedValue;
              address.Country = ddlCountry.SelectedValue;
              address.PostalCode = txtPostalCode.Text;
              address.UserName = WebUtility.GetUserName();
              address.AddressType = addressType;

              _user.AddressCollection.Add(address);
              _user.Save();

              LoadAddresses();
              pnlEditAddress.Visible = false;
              pnlBillingAddresses.Visible = true;
              pnlShippingAddresses.Visible = true;

              tcMyAccount.ActiveTab = tpAddresses;
        }