コード例 #1
0
        public virtual void OnPageRedirected(object sender, EventArgs e)
        {
            var eventArgumets = e as PageRedirectedEventArgs;

            if (eventArgumets != null)
            {
                RedirectProcessor.UpdateLastUseInThread(eventArgumets);
                LogManager.WriteInfo($"Update last use for {eventArgumets.RedirectId} is completed");
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks the acceptable page mode and args and redirect page if needed
        /// </summary>
        /// <param name="args">The args.</param>
        public override void Process(HttpRequestArgs args)
        {
            Assert.ArgumentNotNull(args, "RedirectManager");

            if (!Configuration.Enabled)
            {
                return;
            }

            try
            {
                if (!Configuration.RedirectsListIsInitialized)
                {
                    Configuration.RedirectsListIsInitialized = true;
                    RedirectProcessor.Initialize();
                    RedirectProcessor.CreateListOfRedirectsInThread();
                }
            }
            catch (Exception e)
            {
                LogManager.WriteError(e.Message);
                LogManager.WriteError(e.StackTrace);
            }

            if (Context.Item != null)
            {
                CyclingProtectionManager.ClearCurrentCycle(args.Context.Response, args.Context.Request);
                if (RedirectProcessor.CheckPresentation(Context.Item))
                {
                    return;
                }
            }

            if (!CheckPageMode() || Context.Database == null || Context.Request.FilePath == null ||
                Context.Database.Name == "core" || CheckIgnorePages())
            {
                CyclingProtectionManager.ClearCurrentCycle(args.Context.Response, args.Context.Request);
                return;
            }

            if (!CyclingProtectionManager.CheckCycle(args.Context.Response, args.Context.Request))
            {
                LogManager.WriteInfo(string.Format("Reached limit of cycles for the request: \"{0}\"", Context.Request.FilePath));
                CyclingProtectionManager.ClearCurrentCycle(args.Context.Response, args.Context.Request);
                return;
            }

            var sw = new Stopwatch();

            sw.Start();

            int    redirectCode;
            string redirectId;
            var    baseUrl   = UrlNormalizer.CheckPageExtension(UrlNormalizer.Normalize(Context.Request.FilePath, true));
            var    targetUrl = RedirectProcessor.FindRedirect(baseUrl, out redirectCode, out redirectId);

            if (string.IsNullOrEmpty(targetUrl))
            {
                if (Configuration.EnableNotFounds)
                {
                    LogManager.WriteInfo(string.Format("Redirect for the page: \"{0}\" was not found", Context.Request.FilePath));
                }

                CyclingProtectionManager.ClearCurrentCycle(args.Context.Response, args.Context.Request);
                return;
            }

            RedirectProcessor.UpdateLastUseInThread(redirectId);
            sw.Stop();
            LogManager.WriteInfo(
                string.Format(
                    "Page \"{0}\" was redirected to \"{1}\": redirect item id - {2}, elapsed time - {3} milliseconds",
                    Context.Request.FilePath,
                    targetUrl,
                    redirectId,
                    sw.ElapsedMilliseconds));

            Response(args, targetUrl, redirectCode);
        }