<commit_before>﻿using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using DirigoEdge.Data.Context;
using DirigoEdge.Models.Shortcodes;
using DirigoEdgeCore.Data.Entities;
using DirigoEdgeCore.PluginFramework;
using DirigoEdgeCore.Utils;
using DirigoEdgeCore.Utils.Logging;
using log4net.Config;

namespace DirigoEdge
{
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            XmlConfigurator.Configure();
            var log = LogFactory.GetLog(typeof(MvcApplication));
            log.Debug("Starting edge");

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            var rc = RouteTable.Routes;

            using (var context = new WebDataContext())
            {
                context.Database.Initialize(false);
            }

            // Registers Containing Area, such as /Admin
            AreaRegistration.RegisterAllAreas();

            // Register the stock routes plus the plugin routes
            RouteConfig.RegisterRoutes(rc);

            // Add the new View Engine for our plugins to use
            ViewEngines.Engines.Add(new PluginRazorViewEngine());

            // Register new dynamic modules/shortcodes
            DynamicModules.Instance.AddDynamicModule("responsive_image", new ResponsiveImageShortcode());
            DynamicModules.Instance.AddDynamicModule("featured_events", new EventsModule());

            Mapping.SetAutomapperMappings();
        }

        // May need to store host in distributed or multi-tenant applications
        protected void Application_BeginRequest()
        {
            // Find out if the redirect exists for this request path

            var allRedirects = CachedObjects.GetRedirectsList(false);

            if (allRedirects == null)
            {
                return;

            }

            Redirect redirect = allRedirects
                .FirstOrDefault(
                    x => (x.Source == Request.Path || x.Source + '/' == Request.Path || x.Source == Request.Path + '/')
                         || (x.RootMatching && Request.Path.StartsWith(x.Source) && !Request.Path.StartsWith(x.Destination)));

            // Check whether the browser remains connected to the server.
            if (!Response.IsClientConnected)
            {
                // If the browser is not connected stop all response processing.
                Response.End();
                return;
            }
            
            if (redirect == null)
            {
                return;
            }

            if (redirect.IsPermanent)
            {
                Response.RedirectPermanent(redirect.Destination);
            }
            else
            {
                // If still connected, redirect to another page.
                Response.Redirect(redirect.Destination);
            }
        }
    }
}<commit_msg>Fixed the issue where /blog/whatever can't redirect to /blog<commit_after>﻿using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using DirigoEdge.Data.Context;
using DirigoEdge.Models.Shortcodes;
using DirigoEdgeCore.Data.Entities;
using DirigoEdgeCore.PluginFramework;
using DirigoEdgeCore.Utils;
using DirigoEdgeCore.Utils.Logging;
using log4net.Config;

namespace DirigoEdge
{
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            XmlConfigurator.Configure();
            var log = LogFactory.GetLog(typeof(MvcApplication));
            log.Debug("Starting edge");

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            var rc = RouteTable.Routes;

            using (var context = new WebDataContext())
            {
                context.Database.Initialize(false);
            }

            // Registers Containing Area, such as /Admin
            AreaRegistration.RegisterAllAreas();

            // Register the stock routes plus the plugin routes
            RouteConfig.RegisterRoutes(rc);

            // Add the new View Engine for our plugins to use
            ViewEngines.Engines.Add(new PluginRazorViewEngine());

            // Register new dynamic modules/shortcodes
            DynamicModules.Instance.AddDynamicModule("responsive_image", new ResponsiveImageShortcode());
            DynamicModules.Instance.AddDynamicModule("featured_events", new EventsModule());

            Mapping.SetAutomapperMappings();
        }

        // May need to store host in distributed or multi-tenant applications
        protected void Application_BeginRequest()
        {
            // Find out if the redirect exists for this request path

            var allRedirects = CachedObjects.GetRedirectsList(false);

            if (allRedirects == null)
            {
                return;

            }

            Redirect redirect = allRedirects
                .FirstOrDefault(
                    x => (x.Source == Request.Path || x.Source + '/' == Request.Path || x.Source == Request.Path + '/')
                         || (x.RootMatching && Request.Path.StartsWith(x.Source)));

            // Check whether the browser remains connected to the server.
            if (!Response.IsClientConnected)
            {
                // If the browser is not connected stop all response processing.
                Response.End();
                return;
            }
            
            if (redirect == null)
            {
                return;
            }

            if (redirect.IsPermanent)
            {
                Response.RedirectPermanent(redirect.Destination);
            }
            else
            {
                // If still connected, redirect to another page.
                Response.Redirect(redirect.Destination);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08381799521040027, 'fraction_numerical': 0.00034211426616489907, 'mean_word_length': 1.78826895565093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7215684', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1373, 'n_words': 345}