protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // checking if the user is in active session, if not redirecting to login page if (Session["StaffAccount"] != null) { GeneralUserClass staff = (GeneralUserClass)Session["StaffAccount"]; LabelUsername.Text = staff.username; } else { Response.Redirect("~/StaffLogin.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { // the code that only needs to run once goes here if (!IsPostBack) { // checking if the user is in active session, if not redirecting to login page if (Session["MemberAccount"] != null) { GeneralUserClass member = (GeneralUserClass)Session["MemberAccount"]; LabelUsername.Text = member.username; } else { Response.Redirect("~/MemberLogin.aspx"); } } }
protected void ButtonLogin_Click(object sender, EventArgs e) { string userName = loginControl.UserName; string password = loginControl.Password; if (userName.Equals("") || password.Equals("")) { LabelLoginError.Visible = true; LabelLoginError.Text = "Please enter username & password"; } else { UserXmlManipulation staffXml = new UserXmlManipulation(); bool isValidUser = staffXml.AuthenticateUserCredential(userName, password, STAFF_XML); if (isValidUser) { // storing the user information in the session for future use GeneralUserClass staff = new GeneralUserClass(); staff.username = userName; Session["StaffAccount"] = staff; // storing username in a cookie if user checks the checkbox at UI if (CheckBoxSaveUsername.Checked == true) { HttpCookie myCookies = new HttpCookie("staffLoginCookie"); myCookies["UserName"] = loginControl.UserName; myCookies.Expires = DateTime.Now.AddMinutes(5); Response.Cookies.Add(myCookies); } Response.Redirect("~/Staff.aspx"); } else { LabelCookie.Visible = true; LabelCookie.Text = "Wrong username/password entered..!"; } } }