protected void Page_Load(object sender, EventArgs e) { HttpContext context = HttpContext.Current; if (context.Request.Url.AbsoluteUri.ToUpper().Contains("BETA")) // ) || (context.Request.IsLocal)) { // MainBody.Attributes.Add("bgcolor", "LightCyan"); MainBody.Attributes.Add("style", "background-color: LightCyan"); } if (!IsPostBack) { if (Session["CurrentPagePermission"].ToString() == "False") { if (Session["AlternatePageURL"] != null) { string AltURL = Session["AlternatePageURL"].ToString(); Session["CurrentPagePermission"] = "True"; Session["LastLoggedInLocation"] = AltURL; //Response.Redirect(AltURL); Rick - 10/11/2015 - Remove comment when security works } } string PageName = Request.Url.AbsolutePath + ".aspx"; Session["LastLoggedInLocation"] = PageName; if (Session["LastWrittenLoggedInLocation"] != null && Session["LastWrittenLoggedInLocation"] == Session["LastLoggedInLocation"]) { // Do nothing } else { int ExclusionCount = 0; if (Session["ExclusionCount"] == null) { Session["ExclusionCount"] = 0; } if (Session["PageName"] == null) { Session["PageName"] = PageName; } else { if (Session["PageName"] == PageName) { Int32.TryParse(Session["ExclusionCount"].ToString(), out ExclusionCount); } else { string lsRoutineName = "LARPortal.Master.PageNameContainCheck"; string stStoredProc = "uspCheckForExclusion"; string strUserName = Session["UserName"].ToString(); SortedList slParams = new SortedList(); slParams.Add("@CompareString", PageName); slParams.Add("@ExclusionType", "LastLoggedInLocation"); DataTable dtExclusionCheck = cUtilities.LoadDataTable(stStoredProc, slParams, "LARPortal", strUserName, lsRoutineName); foreach (DataRow dRow in dtExclusionCheck.Rows) { Int32.TryParse(dRow["Exclude"].ToString(), out ExclusionCount); } } } //if (PageName.Contains("Error") || PageName.Contains("WhatsNewDetail") || PageName.Contains("Reports/") || PageName.Contains("EventPayment") || PageName.Contains("PageUnderConstruction")) if (ExclusionCount > 0) { // It met at least one exclusion criteria. Do nothing. } else { // Set them equal and write to MDBUser LastLoggedInLocation Session["LastWrittenLoggedInLocation"] = Session["LastLoggedInLocation"]; Classes.cLogin LastLoggedIn = new Classes.cLogin(); if (Session["UserID"] != null) { int intUserID = Session["UserID"].ToString().ToInt32(); LastLoggedIn.LogLastPage(intUserID, PageName); } } } // Check page security // Check request.rawurl against cURLPermission // Go get all roles for that campaign and load them into a session variable int UserID = Convert.ToInt32(Session["UserID"]); int CampaignID = Convert.ToInt32(Session["CampaignID"]); Classes.cPlayerRoles Roles = new Classes.cPlayerRoles(); Roles.Load(UserID, 0, CampaignID, DateTime.Today); Session["PlayerRoleString"] = Roles.PlayerRoleString; Classes.cURLPermission permissions = new Classes.cURLPermission(); bool PagePermission = true; string DefaultUnauthorizedURL = ""; permissions.GetURLPermissions(Request.RawUrl, UserID, Roles.PlayerRoleString); PagePermission = permissions._PagePermission; DefaultUnauthorizedURL = permissions._DefaultUnauthorizedURL; if (PagePermission == false) { Response.Redirect(DefaultUnauthorizedURL); } // End permission check } // Uncomment this if trying to run the page without going through the index.aspx page //Session["SecurityRole"] = 0; int i; int intSecurityRole; if (Session["CampaignName"] == null) { Session["CampaignName"] = ""; } //lblCampaignName.Text = Session["CampaignName"].ToString(); if (Session["LoginName"] == null) { Session["LoginName"] = "Guest"; } //lblLoginName.Text = "Welcome " + Session["LoginName"].ToString(); if (int.TryParse(Session["SecurityRole"].ToString(), out i)) { intSecurityRole = i; } else { intSecurityRole = 0; } LoadMainLinks(); LoadTopTab(intSecurityRole, 0); //TODO-Rick-2 Change second variable to a session variable as defined by Jeff's communications section LoadPageFooter(); if (Session["PageFooter"] == null) { Session["PageFooter"] = " "; } lblPageFooter.Text = Session["PageFooter"].ToString(); }
protected void Page_PreRender(object sender, EventArgs e) { //if (Request.Url.Host.ToUpper().Contains("BETA.")) //{ // lblMessage.Text = "Beta Site"; // SqlConnectionStringBuilder ConnPieces = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["LARPortal"].ConnectionString); // if (ConnPieces != null) // lblMessage.Text += " Database: " + ConnPieces.InitialCatalog; //} //else if (Request.Url.Host.ToUpper().Contains("LOCALHOST")) //{ // lblMessage.Text = "Local Host"; // SqlConnectionStringBuilder ConnPieces = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["LARPortal"].ConnectionString); // if (ConnPieces != null) // lblMessage.Text += " Database: " + ConnPieces.InitialCatalog; //} if (Session["CompileDate"] is null) { DateTime dtCompileTime = Classes.cCompileDate.GetLinkerDateTime(Assembly.GetExecutingAssembly()); string sCompileTime = "Compiled: " + dtCompileTime.ToString("g", CultureInfo.CreateSpecificCulture("en-US")); Session["CompileDate"] = sCompileTime; } SqlConnectionStringBuilder ConnPieces = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["LARPortal"].ConnectionString); if (ConnPieces != null) { lblMessage.Text = Session["CompileDate"].ToString() + " Database: " + ConnPieces.InitialCatalog; } lblMessage.ForeColor = System.Drawing.Color.Transparent; if ((Session["SuperUser"] != null) || (Request.Url.Host.ToUpper().Contains("BETA.")) || (Request.Url.Host.ToUpper().Contains("LOCALHOST"))) { lblMessage.ForeColor = System.Drawing.Color.White; } Classes.cLogin SiteFooter = new Classes.cLogin(); SiteFooter.SetPageFooter(); lblFooter.Text = SiteFooter.SiteFooter; if ((!IsPostBack) || (Session["ReloadCampaigns"] != null)) { if (Session["ReloadCampaigns"] != null) { Session.Remove("CampaignID"); Session.Remove("CampaignName"); Session.Remove("CampaignList"); Session.Remove("RoleString"); } Session.Remove("ReloadCampaigns"); if (Session["Guest"] != null) { mvMenuArea.SetActiveView(vwGuest); lblUserName.Text = "Guest"; return; } mvMenuArea.SetActiveView(vwFullMenu); lblUserName.Text = Session["UserName"].ToString(); if (!DisplayAllOptions) { if (Session["CampaignID"] != null) { int iCampaignID; if (int.TryParse(Session["CampaignID"].ToString(), out iCampaignID)) { if (iCampaignID < 0) { Session.Remove("CampaignID"); } } } } LoadData(); } Classes.cPlayerRoles Roles = new Classes.cPlayerRoles(); Roles.Load(UserID, 0, CampaignID, DateTime.Today); Classes.cURLPermission permissions = new Classes.cURLPermission(); bool PagePermission = true; string DefaultUnauthorizedURL = ""; string CurrentPage = Request.RawUrl; if (CurrentPage.ToUpper().EndsWith(".ASPX")) { CurrentPage = CurrentPage.Substring(0, CurrentPage.Length - 5); } permissions.GetURLPermissions(CurrentPage, UserName, Roles.PlayerRoleString); PagePermission = permissions.PagePermission; DefaultUnauthorizedURL = permissions.DefaultUnauthorizedURL; if (!PagePermission) { Response.Redirect(DefaultUnauthorizedURL); } // Save current page to database so when person logs back in it can go to last page. string PageName = Request.Url.AbsolutePath; Classes.cLogin LastLoggedIn = new Classes.cLogin(); LastLoggedIn.LogLastPage(UserID, PageName); }
protected void ddlUserCampaigns_SelectedIndexChanged(object sender, EventArgs e) { if (ddlUserCampaigns.SelectedValue == "-1") { Response.Redirect("~/PublicCampaigns.aspx"); } int intUserID; string SelectedText; string SelectedValue; SelectedText = ddlUserCampaigns.SelectedItem.Text.ToString(); SelectedValue = ddlUserCampaigns.SelectedItem.Value.ToString(); if (Session["UserID"] == null) { intUserID = -1; // In theory we can't actually get here so we should just go back to login Response.Redirect("~/index.aspx"); } else { intUserID = Session["UserID"].ToString().ToInt32(); } Classes.cUser User = new Classes.cUser(Session["Username"].ToString(), "PasswordNotNeeded"); User.UserID = intUserID; User.LastLoggedInCampaign = ddlUserCampaigns.SelectedItem.Value.ToInt32(); Session["CampaignID"] = ddlUserCampaigns.SelectedItem.Value.ToInt32(); Session["CampaignName"] = ddlUserCampaigns.SelectedItem.Text.ToString(); User.SetCharacterForCampaignUser(intUserID, ddlUserCampaigns.SelectedItem.Value.ToInt32()); Session["SelectedCharacter"] = User.LastLoggedInCharacter; User.LastLoggedInMyCharOrCamp = "M"; // 5/27/2017-RPierce - If switching campaign list, assume switching to my characters on character tab User.Save(); // 5/27/2018 - RPierce - Remove Campaign Character session variables if (Session["CharacterCampaignCharID"] != null) { Session.Remove("CharacterCampaignCharID"); } if (Session["CharacterSelectCampaign"] != null) { Session.Remove("CharacterSelectCampaign"); } if (Session["CharacterSelectGroup"] != null) { Session.Remove("CharacterSelectGroup"); } if (Session["CharacterSelectID"] != null) { Session.Remove("CharacterSelectID"); } if (Session["CampaignsToEdit"] != null) { Session.Remove("CampaignsToEdit"); } if (Session["MyCharacters"] != null) { Session.Remove("MyCharacters"); } // Go get all roles for that campaign and load them into a session variable Classes.cPlayerRoles Roles = new Classes.cPlayerRoles(); Roles.Load(intUserID, 0, ddlUserCampaigns.SelectedItem.Value.ToInt32(), DateTime.Today); Session["PlayerRoleString"] = Roles.PlayerRoleString; Classes.cURLPermission permissions = new Classes.cURLPermission(); bool PagePermission = true; string DefaultUnauthorizedURL = ""; permissions.GetURLPermissions(Request.RawUrl, intUserID, Roles.PlayerRoleString); PagePermission = permissions._PagePermission; DefaultUnauthorizedURL = permissions._DefaultUnauthorizedURL; string ReportCheck = Request.RawUrl.Substring(0, 8); if (PagePermission == true) { if (ReportCheck == "/Reports") { Response.Redirect("/Reports/ReportsList.aspx"); } else { Response.Redirect(Request.RawUrl); } } else { Response.Redirect(DefaultUnauthorizedURL); } }