Beispiel #1
0
        public static void RedirectToSignInPage(string returnUrl,
                                                QueryStringCollection qsc)
        {
            string queryString = null;

            if ((qsc != null) && (qsc.Count > 0))
            {
                queryString = qsc.ToString();
            }
            RedirectToSignInPage(returnUrl, queryString);
        }
        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);
        }
Beispiel #3
0
 public static Uri GetSiteUri(string path, QueryStringCollection qsc)
 {
     return(GetSiteUri(path, qsc.ToString()));
 }
Beispiel #4
0
 public static Uri GetDomainDesignCodeUri(
     string designCode, string path, QueryStringCollection qsc)
 {
     return(GetDomainDesignCodeUri(designCode, path, qsc.ToString()));
 }
Beispiel #5
0
 public static Uri GetCurrentSiteUri(QueryStringCollection qsc)
 {
     return(GetCurrentSiteUri(null, qsc.ToString()));
 }
Beispiel #6
0
 public static Uri GetCurrentPathUri(QueryStringCollection qsc)
 {
     return(GetCurrentPathUri(qsc.ToString()));
 }