protected void TestButton_Click(object sender, EventArgs e) { string requestUrl = RequestUrl.Text.Trim(); String redirectUrl = requestUrl; int appliedRedirectsCount = 0; int appliedRedirectsLimit = 20; StringBuilder redirectionLog = new StringBuilder(); String applicationPath = Request.ApplicationPath; if (!applicationPath.EndsWith("/")) { applicationPath += "/"; } // Have application-wide rewrite option bool rewriteEnabled = ApplicationSettings.Instance.UrlRewriterEnabled; string tempUrl = String.Empty; do { // BACKUP THE REQUESTED URL BEFORE APPLYING RULES tempUrl = redirectUrl; // CHECK FOR 301 REDIRECT IRedirectService redirectService = AbleContext.Resolve <IRedirectService>(); Redirect r = redirectService.LocateRedirect(redirectUrl); if (r != null) { redirectUrl = r.ApplyToUrl(redirectUrl); // CHECK IF THE REDIRECT URL IS CHANGED if (!tempUrl.Equals(redirectUrl, StringComparison.InvariantCultureIgnoreCase)) { appliedRedirectsCount++; redirectionLog.Append(" is redirected to ").Append("<br/>").Append(applicationPath).Append(redirectUrl).Append("<br/>"); } } else { // CHECK FOR REWRITE RULES // BACKUP THE REQUESTED URL BEFORE APPLYING RULES tempUrl = redirectUrl; if (rewriteEnabled) { String rewriteUrl = GetRewriteUrl(redirectUrl); // CHECK IF THE REDIRECT URL IS CHANGED if (!tempUrl.Equals(rewriteUrl, StringComparison.InvariantCultureIgnoreCase)) { appliedRedirectsCount++; redirectionLog.Append(" is rewritten to ").Append("<br/>").Append(applicationPath).Append(rewriteUrl).Append("<br/>"); } } } } while (!tempUrl.Equals(redirectUrl, StringComparison.InvariantCultureIgnoreCase) && appliedRedirectsCount < appliedRedirectsLimit); ResultsPanel.Visible = true; ResultsCaption.Text = String.Format(ResultsCaption.Text, requestUrl); if (appliedRedirectsCount > 0) { ResultsLabel.Visible = true; ResultsLabel.Text = String.Format(ResultsLabel.Text, applicationPath + requestUrl, redirectionLog.ToString()); if (appliedRedirectsCount >= appliedRedirectsLimit) { CircularRedirectsLabel.Visible = true; } } else { NoResultsLabel.Visible = true; } }