コード例 #1
0
        /// <summary>
        /// Short URLs and moved pages are stored in a database. See whether there's a match, and redirect.
        /// </summary>
        /// <param name="requestedUrl">The requested URL.</param>
        private bool TryShortOrMovedUrl(Uri requestedUrl)
        {
            try
            {
                // Try to match the requested URL to a redirect and, if successful, run handlers for the redirect
                var matchers = new IRedirectMatcher[] { new SqlServerRedirectMatcher()
                                                        {
                                                            ThrowErrorOnMissingConfiguration = false
                                                        } };
                var handlers = new IRedirectHandler[] { new ConvertToAbsoluteUrlHandler(), new PreserveQueryStringHandler(), new DebugInfoHandler(), new GoToUrlHandler() };

                foreach (var matcher in matchers)
                {
                    var redirect = matcher.MatchRedirect(requestedUrl);
                    if (redirect != null)
                    {
                        foreach (var handler in handlers)
                        {
                            redirect = handler.HandleRedirect(redirect);
                        }
                        return(true);
                    }
                }
            }
            catch (SqlException ex)
            {
                // If there's a problem, publish the error and continue to show 404 page
                ex.ToExceptionless().Submit();
            }
            return(false);
        }
コード例 #2
0
 public HttpStatusController(IEastSussexGovUKTemplateRequest templateRequest, IViewModelDefaultValuesProvider defaultModelValues, INotFoundRequestPathResolver notFoundRequestPathResolver, IRedirectMatcher redirectMatcher, IConvertToAbsoluteUrlHandler convertToAbsoluteUrlHandler, IPreserveQueryStringHandler preserveQueryStringHandler)
 {
     _templateRequest             = templateRequest;
     _defaultModelValues          = defaultModelValues;
     _notFoundRequestPathResolver = notFoundRequestPathResolver;
     _redirectMatcher             = redirectMatcher;
     _convertToAbsoluteUrlHandler = convertToAbsoluteUrlHandler;
     _preserveQueryStringHandler  = preserveQueryStringHandler;
 }
コード例 #3
0
        private void RedirectsModule_BeginRequest(object sender, EventArgs e)
        {          
            try
            {
                // If the requested path exists, or it's too long for MapPath to handle, do nothing
                try
                {
                    if (File.Exists(HostingEnvironment.MapPath(HttpContext.Current.Request.Url.AbsolutePath)))
                    {
                        return;
                    }
                }
                catch (PathTooLongException)
                {

                    return;
                }

                // If the requested path matches an ignored pattern, do nothing
                if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["Escc.Redirects.IgnorePaths"]))
                {
                    var ignorePaths = ConfigurationManager.AppSettings["Escc.Redirects.IgnorePaths"].Split(',');
                    foreach (var ignorePath in ignorePaths)
                    {
                        if (Regex.IsMatch(HttpContext.Current.Request.Url.PathAndQuery, ignorePath, RegexOptions.IgnoreCase))
                        {
                            return;
                        }
                    }
                }

                // Try to match the requested URL to a redirect and, if successful, run handlers for the redirect
                var matchers = new IRedirectMatcher[] {new SqlServerRedirectMatcher()};
                var handlers = new IRedirectHandler[] {new ConvertToAbsoluteUrlHandler(), new PreserveQueryStringHandler(), new DebugInfoHandler(), new GoToUrlHandler()};

                foreach (var matcher in matchers)
                {
                    var redirect = matcher.MatchRedirect(HttpContext.Current.Request.Url);
                    if (redirect != null)
                    {
                        foreach (var handler in handlers)
                        {
                            redirect = handler.HandleRedirect(redirect);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // If there's a problem, publish the error and continue
                ex.ToExceptionless().Submit();
            }
        }
コード例 #4
0
        private void RedirectsModule_BeginRequest(object sender, EventArgs e)
        {
            try
            {
                // If the requested path exists, or it's too long for MapPath to handle, do nothing
                try
                {
                    if (File.Exists(HostingEnvironment.MapPath(HttpContext.Current.Request.Url.AbsolutePath)))
                    {
                        return;
                    }
                }
                catch (PathTooLongException)
                {
                    return;
                }

                // If the requested path matches an ignored pattern, do nothing
                if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["Escc.Redirects.IgnorePaths"]))
                {
                    var ignorePaths = ConfigurationManager.AppSettings["Escc.Redirects.IgnorePaths"].Split(',');
                    foreach (var ignorePath in ignorePaths)
                    {
                        if (Regex.IsMatch(HttpContext.Current.Request.Url.PathAndQuery, ignorePath, RegexOptions.IgnoreCase))
                        {
                            return;
                        }
                    }
                }

                // Try to match the requested URL to a redirect and, if successful, run handlers for the redirect
                var matchers = new IRedirectMatcher[] { new SqlServerRedirectMatcher() };
                var handlers = new IRedirectHandler[] { new ConvertToAbsoluteUrlHandler(), new PreserveQueryStringHandler(), new DebugInfoHandler(), new GoToUrlHandler() };

                foreach (var matcher in matchers)
                {
                    var redirect = matcher.MatchRedirect(HttpContext.Current.Request.Url);
                    if (redirect != null)
                    {
                        foreach (var handler in handlers)
                        {
                            redirect = handler.HandleRedirect(redirect);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // If there's a problem, publish the error and continue
                ex.ToExceptionless().Submit();
            }
        }