protected internal virtual bool RedirectIfTrailingSlashIsMissing() { var redirectInformation = new RedirectInformation(); var url = this.WebFacade.Request.Url; if (url != null && !url.LocalPath.EndsWith("/", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(Path.GetExtension(url.LocalPath))) { var uriBuilder = new UriBuilder(url); uriBuilder.Path += "/"; redirectInformation.Url = uriBuilder.Uri; } if (!redirectInformation.Redirect) { return(false); } this.LogDebugIfEnabled(string.Format(CultureInfo.InvariantCulture, "The path must end with a slash. Redirecting from {0} to {1}.", this.WebFacade.Request.Url, redirectInformation.Url), "RedirectIfTrailingSlashMissing"); this.WebFacade.Response.Redirect(redirectInformation.Url.ToStringValue(), false); this.WebFacade.Context.ApplicationInstance.CompleteRequest(); return(true); }
public virtual IRedirectInformation Create() { var redirectInformation = new RedirectInformation(); var returnUrlValue = this.WebFacade.Request.QueryString[this.ReturnUrlParameterName]; // ReSharper disable InvertIf if (!string.IsNullOrEmpty(returnUrlValue)) { if (!Uri.TryCreate(returnUrlValue, UriKind.RelativeOrAbsolute, out var returnUrl)) { redirectInformation.Exception = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Could not create an url from the value \"{0}\".", returnUrlValue)); } else { redirectInformation.Url = this.GetRedirectUrl(returnUrl); if (redirectInformation.Url.IsAbsoluteUri && !this.IsUrlWithinAppRoot(redirectInformation.Url)) { var redirectUrlValue = redirectInformation.Url.ToStringValue(); redirectInformation.Exception = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The url \"{0}\", resolved from return-url \"{1}\", is not a valid redirect-url.", redirectUrlValue, returnUrlValue)); } } } // ReSharper restore InvertIf return(redirectInformation); }