Example #1
0
        public virtual bool HandleRequest(Uri referrer, Uri urlNotFound, out CustomRedirect foundRedirect)
        {
            var redirect = _redirectHandler.Find(urlNotFound);

            foundRedirect = null;

            if (redirect != null)
            {
                // Url has been deleted from this site
                if (redirect.State.Equals((int)RedirectState.Deleted))
                {
                    foundRedirect = redirect;
                    return(true);
                }

                if (redirect.State.Equals((int)RedirectState.Saved))
                {
                    // Found it, however, we need to make sure we're not running in an
                    // infinite loop. The new url must not be the referrer to this page
                    if (string.Compare(redirect.NewUrl, urlNotFound.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) != 0)
                    {
                        foundRedirect = redirect;
                        return(true);
                    }
                }
            }
            else
            {
                // log request to database - if logging is turned on.
                if (_configuration.Logging == LoggerMode.On)
                {
                    // Safe logging
                    var logUrl = _configuration.LogWithHostname ? urlNotFound.ToString() : urlNotFound.PathAndQuery;
                    _requestLogger.LogRequest(logUrl, referrer?.ToString());
                }
            }
            return(false);
        }
Example #2
0
 private void WhenRedirectFound(CustomRedirect redirect)
 {
     A.CallTo(() => _redirectHandler.Find(A <Uri> ._, A <Uri> ._)).Returns(redirect);
 }