protected void Page_Load(object sender, EventArgs e) { #region AdminValidation; // Gets the user's id from the session int currentUser; bool parseUser = int.TryParse(HttpContext.Current.User.Identity.Name.ToString(), out currentUser); // If no username, return to Login page if (!parseUser) { Response.Redirect("~/Default.aspx"); } Update_Instructor(); Refresh_Instructor(); // Sends the user id to the Admin validator and redirects to the correct page if invalid user AdminVal validAdmin = new AdminVal(currentUser); string page = validAdmin.VerifyAccess(); if (page.Length > 0) { Response.Redirect(page); } #endregion ; if (!IsPostBack) { this.BindGrid(); } try { // Grab Class ID from gridview selection currentUser = Int32.Parse(HttpContext.Current.User.Identity.Name.ToString()); //UserText.InnerHtml = "Hello" + currentUser; } catch (Exception) { //Return user to Login Page with error not logged in } }
protected void Page_Load(object sender, EventArgs e) { #region AdminValidation; // Gets the user's ID and Name from the session int currentUser; bool parseUser = int.TryParse(HttpContext.Current.User.Identity.Name.ToString(), out currentUser); // If no username, return to Login page if (!parseUser) { Response.Redirect("~/Default.aspx"); } string constr = ConfigurationManager.ConnectionStrings["CS414_FasTestConnectionString"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("Get_Users_Name")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pUserID", currentUser); cmd.Parameters.Add("@UsersName", SqlDbType.VarChar, 50).Direction = ParameterDirection.ReturnValue; cmd.Connection = con; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); LoginNames.InnerHtml = reader.GetString(0); con.Close(); } } // Sends the user id to the Admin validator and redirects to the correct page if invalid user AdminVal validAdmin = new AdminVal(currentUser); string page = validAdmin.VerifyAccess(); if (page.Length > 0) { Response.Redirect(page); } #endregion ; }