private static string GetAdminFolderPageUrl(string pageName, bool addAdminCodes, params string[] queryParametersAndValues) { IEnumerable <string> queries = queryParametersAndValues; if (addAdminCodes) { var page = GetPage <SecureAdminPage>(); var list = new List <string>(queryParametersAndValues); queries = list; list.Add("state", page.StateCode); if (page.CountyCodeExists) { list.Add("county", page.CountyCode); } if (page.LocalKeyExists) { list.Add("local", page.LocalKey); } } return(UrlManager.ToAdminUrl(QueryStringCollection.FromPairs(queries) .AddToPath("/admin/" + pageName + ".aspx"))); }
protected void Page_Load(object sender, EventArgs e) { var congress = Request.QueryString["Congress"]; var stateCode = Request.QueryString["State"]; var stateSenate = Request.QueryString["StateSenate"]; var stateHouse = Request.QueryString["StateHouse"]; var county = Request.QueryString["County"]; var district = Request.QueryString["District"]; var place = Request.QueryString["Place"]; var elementary = Request.QueryString["Esd"]; var secondary = Request.QueryString["Ssd"]; var unified = Request.QueryString["Usd"]; var cityCouncil = Request.QueryString["Cc"]; var countySupervisors = Request.QueryString["Cs"]; var schoolDistrictDistrict = Request.QueryString["Sdd"]; var geo = Request.QueryString["Geo"]; var page = Request.QueryString["Page"]; var address = Request.QueryString["Address"]; var components = Request.QueryString["Components"]; var remember = !Request.QueryString["Remember"].IsEqIgnoreCase("n"); if (!IsNullOrWhiteSpace(congress) && !IsNullOrWhiteSpace(stateSenate) && Offices.IsValidStateHouseDistrict(stateHouse, stateCode) && !IsNullOrWhiteSpace(county) && !IsNullOrWhiteSpace(components) && !IsNullOrWhiteSpace(geo) && !IsNullOrWhiteSpace(page)) { var expiration = DateTime.UtcNow.AddDays(30); // 30 days var cookie = new HttpCookie("State", IsNullOrWhiteSpace(stateCode) ? DomainData.FromQueryStringOrDomain : stateCode); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Congress", congress); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("StateSenate", stateSenate); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("StateHouse", stateHouse); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("County", county); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("District", district); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Place", place); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Elementary", elementary); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Secondary", secondary); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Unified", unified); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("CityCouncil", cityCouncil); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("CountySupervisors", countySupervisors); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("SchoolDistrictDistrict", schoolDistrictDistrict); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Geo", geo); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Address", address); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("Components", components); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); cookie = new HttpCookie("CDate", HttpUtility.UrlEncode(expiration.ToString(CultureInfo.InvariantCulture))); if (remember) { cookie.Expires = expiration; } Response.Cookies.Add(cookie); if (UrlManager.CurrentDomainDataCode == "US") { var ub = new UriBuilder(UrlNormalizer.BuildCurrentUri()) { Host = UrlManager.GetStateHostName(stateCode) }; Response.Redirect(ub.ToString()); } else { page = HttpUtility.UrlDecode(page); Debug.Assert(page != null, "page != null"); Response.Redirect(page); } } else { Response.Redirect("/404.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { Response.RedirectPermanent(UrlManager.GetIntroPageUri(QueryId) .ToString(), true); }
protected override string GetCacheKey() { return($"{UrlManager.GetStateCodeFromHostName()}.{QueryState}.{QueryId}"); }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); UrlManager.ForceUsaDomain(); }
private void Page_Load(object sender, EventArgs e) { Response.RedirectPermanent( UrlManager.GetForVotersPageUri(DomainData.FromQueryStringOrDomain) .ToString(), true); }
protected override string GetCacheKey() { return(UrlManager.GetStateCodeFromHostName()); }
protected override string GetCacheKey() { return ($"{UrlManager.GetStateCodeFromHostName()}.{QueryReport}." + $"{QueryState}.{QueryCounty}.{QueryLocal}"); }
private bool Normalize(Uri originalUri) { #region Note // This method rebuilds the old requested url // and a new correct url based on the StateCode for the page. // Both are reconstructed so that the QueryString // parameters are in the same order. // Then they are compared (case insensitive). // // If there is any sort of failure, the method returns false. // The ErrorMessage property contains an explanation. // // If the method returns true (success), the // normalized Uri is available through the NormalizedUri // property. If it is null, no redirect is required. #endregion Note Initialize(originalUri); if (IsIPAddress) // any explicit IP address redirects to main site home page { NormalizedUri = UrlManager.SiteUri; return(true); } // Save the caching values and remove them so they don't trigger a // redirect var noCacheValue = GetQueryParm(VotePage.NoCacheParameter); var cacheDefeatValue = GetQueryParm("X"); var openAllValue = GetQueryParm("openall"); var publicValue = GetQueryParm("public"); if (!string.IsNullOrWhiteSpace(noCacheValue) || !string.IsNullOrWhiteSpace(cacheDefeatValue) || !string.IsNullOrWhiteSpace(openAllValue) || !string.IsNullOrWhiteSpace(publicValue)) { if (!string.IsNullOrWhiteSpace(noCacheValue)) { _OriginalQueryCollection.Remove(VotePage.NoCacheParameter); } if (!string.IsNullOrWhiteSpace(cacheDefeatValue)) { _OriginalQueryCollection.Remove("X"); } if (!string.IsNullOrWhiteSpace(openAllValue)) { _OriginalQueryCollection.Remove("openall"); } if (!string.IsNullOrWhiteSpace(publicValue)) { _OriginalQueryCollection.Remove("public"); } var ub = new UriBuilder(OriginalUri) { Query = _OriginalQueryCollection.ToString() }; OriginalUri = ub.Uri; } // for ballot page, save any friend and choices parameters and remove them string friendValue = null; string choicesValue = null; if (OriginalUri.AbsolutePath.ToLower() == "/ballot.aspx") { friendValue = GetQueryParm("friend"); choicesValue = GetQueryParm("choices"); if (!string.IsNullOrWhiteSpace(friendValue) || !string.IsNullOrWhiteSpace(choicesValue)) { if (!string.IsNullOrWhiteSpace(friendValue)) { _OriginalQueryCollection.Remove("friend"); } if (!string.IsNullOrWhiteSpace(choicesValue)) { _OriginalQueryCollection.Remove("choices"); } var ub = new UriBuilder(OriginalUri) { Query = _OriginalQueryCollection.ToString() }; OriginalUri = ub.Uri; } } if (ScriptHasQueryStringParms()) { if (!string.IsNullOrEmpty(GetQueryParm("Election"))) { if (!string.IsNullOrEmpty(GetQueryParm("Office")) && !string.IsNullOrEmpty(GetQueryParm("Issue"))) { HandleIssuePage(); } else if (!string.IsNullOrEmpty(GetQueryParm("Referendum"))) { HandleReferendumPage(); } else if (!string.IsNullOrEmpty(GetQueryParm("Congress"))) { if (OriginalUri.AbsolutePath.ToLower() == "/issue2.aspx") { HandleIssue2Page(); } else { HandleBallotPage(); } } else if (!string.IsNullOrEmpty(GetQueryParm("Office"))) { HandleCompareCandidatesPage(); } else { HandleElectionPage(); } } else if (!string.IsNullOrEmpty(GetQueryParm("Id"))) { if (!string.IsNullOrEmpty(GetQueryParm("Issue"))) { HandlePoliticianIssuePage(); } else { HandleIntroPage(); } } else if (!string.IsNullOrEmpty(GetQueryParm("Congress"))) { HandleElectedPage(); } else if (!string.IsNullOrEmpty(GetQueryParm("Report")) || !string.IsNullOrEmpty(UrlManager.FindStateCode())) { HandleOfficialsPage(); } } if (NormalizedUri == null) // nothing yet, keep trying { if (ScriptCanHaveStateParm()) { HandlePagesWithOnlyStateCode(); } } if (NormalizedUri == null) // nothing yet, keep trying { if (ScriptHasNoParms()) { HandlePagesWithNoStateCode(); } } // Ensure a canonical host name if (NormalizedUri != null) { if (!UrlManager.IsCanonicalHostName(NormalizedUri.Host)) // replace host { var ub = new UriBuilder(NormalizedUri) { Host = UrlManager.GetCanonicalHostName(NormalizedUri.Host) }; NormalizedUri = ub.Uri; } } // Note: logging has been moved out of the mainstream processing so that // this class can be easily tested without logging if (NormalizedUri == null) // We couldn't do anything with it, error return { return(false); } // The canonical Uri is all lower case CanonicalUri = new Uri(NormalizedUri.ToString() .ToLowerInvariant()); CanonicalUri = AdjustCanonicalUri(CanonicalUri); if ( Uri.Compare(NormalizedUri, OriginalUri, UriComponents.AbsoluteUri | UriComponents.Fragment, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0) { NormalizedUri = null; // meaning no redirect is necessary } // suppress redirect for /default.aspx if everything else is the same if (NormalizedUri != null && OriginalUri.AbsolutePath.Equals("/default.aspx", StringComparison.OrdinalIgnoreCase)) { var ub = new UriBuilder(OriginalUri) { Path = "/" }; if ( Uri.Compare(NormalizedUri, ub.Uri, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0) { NormalizedUri = null; // meaning no redirect is necessary } } // Restore NoCache and browser cache defeat parameters. // Note: we do not restore browser cache defeat unless NoCache is present too. if (NormalizedUri != null && (!string.IsNullOrWhiteSpace(noCacheValue) || !string.IsNullOrWhiteSpace(openAllValue) || !string.IsNullOrWhiteSpace(publicValue))) { var ub = new UriBuilder(NormalizedUri); var qsc = QueryStringCollection.Parse(ub.Query); if (!string.IsNullOrWhiteSpace(noCacheValue)) { qsc.Add(VotePage.NoCacheParameter, noCacheValue); } if (!string.IsNullOrWhiteSpace(noCacheValue) && !string.IsNullOrWhiteSpace(cacheDefeatValue)) { qsc.Add("X", cacheDefeatValue); } if (!string.IsNullOrWhiteSpace(openAllValue)) { qsc.Add("openall", openAllValue); } if (!string.IsNullOrWhiteSpace(publicValue)) { qsc.Add("public", publicValue); } ub.Query = qsc.ToString(); NormalizedUri = ub.Uri; } // restore friend and choices (ballot page only) // must both be present if (NormalizedUri != null && (!string.IsNullOrWhiteSpace(friendValue) && !string.IsNullOrWhiteSpace(choicesValue))) { var ub = new UriBuilder(NormalizedUri); var qsc = QueryStringCollection.Parse(ub.Query); qsc.Add("friend", friendValue); qsc.Add("choices", choicesValue); ub.Query = qsc.ToString(); NormalizedUri = ub.Uri; } // This return indicates lack of failure. The null-ness of NormalizedUri // indicates whether or not to redirect. return(true); }
private void HandlePagesWithOnlyStateCode() { var stateCode = UrlManager.FindStateCode(); if (string.IsNullOrEmpty(stateCode) || StateCache.IsValidStateCode(stateCode)) { switch (OriginalUri.AbsolutePath.ToLower()) { case "/": case "/default.aspx": NormalizedUri = UrlManager.GetDefaultPageUri(stateCode); break; case "/aboutus.aspx": NormalizedUri = UrlManager.GetAboutUsPageUri(stateCode); break; case "/contactus.aspx": NormalizedUri = UrlManager.GetContactUsPageUri(stateCode); break; case "/donate.aspx": NormalizedUri = UrlManager.GetDonatePageUri(stateCode); break; case "/forcandidates.aspx": NormalizedUri = UrlManager.GetForCandidatesPageUri(stateCode); break; case "/forresearch.aspx": NormalizedUri = UrlManager.GetForResearchPageUri(stateCode); break; case "/forpartners.aspx": NormalizedUri = UrlManager.GetForPartnersPageUri(stateCode); break; case "/forpoliticalparties.aspx": NormalizedUri = UrlManager.GetForPoliticalPartiesPageUri(stateCode); break; case "/forelectionauthorities.aspx": NormalizedUri = UrlManager.GetForElectionAuthoritiesPageUri(stateCode); break; case "/forvolunteers.aspx": NormalizedUri = UrlManager.GetForVolunteersPageUri(stateCode); break; case "/forvoters.aspx": NormalizedUri = UrlManager.GetForVotersPageUri(stateCode); break; case "/issuelist.aspx": NormalizedUri = UrlManager.GetIssueListPageUri(stateCode); break; case "/privacy.aspx": NormalizedUri = UrlManager.GetPrivacyPageUri(stateCode); break; } } else { ErrorMessage = "Invalid_StateCode"; } }
private void HandleIntroPage() { var politicianKey = GetQueryParm("Id"); NormalizedUri = UrlManager.GetIntroPageUri(politicianKey); }
protected override void OnPreInit(EventArgs e) { Response.Redirect(UrlManager.GetSiteUri().ToString()); Response.End(); }
private static Uri GetImageUri(string designCode, string imageName) { return(UrlManager.GetDomainDesignCodeUri( designCode, ImagePath(designCode, imageName))); }
protected override string GetCacheKey() { return ($"{UrlManager.GetStateCodeFromHostName()}.{QueryState}.{QueryElection}." + $"{GetQueryString("openall").IsEqIgnoreCase("Y")}"); }
protected override string GetCacheKey() { return ($"{UrlManager.GetStateCodeFromHostName()}.{QueryState}.{QueryElection}.{QueryReferendum}"); }