Beispiel #1
0
        /// <summary>
        /// Gets the page, and based on the Class of the Page, attempts to get the Dynamic routing information and processes.
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            var node = mDynamicRouteHelper.GetPage(AddPageToCacheDependency: false);

            var routePair = ResolveRouteValues(node);

            RequestRoutingEventArgs RequestArgs = new RequestRoutingEventArgs()
            {
                Page                  = node,
                Configuration         = routePair,
                CurrentRequestContext = RequestContext
            };

            // Use event to allow users to overwrite the Dynamic Routing Data
            using (var RequestRoutingHandler = DynamicRoutingEvents.RequestRouting.StartEvent(RequestArgs))
            {
                // Check if the OutputCache was disabled or enabled during the event args
                if (routePair.ControllerName.Equals("DynamicRouteCached", StringComparison.InvariantCultureIgnoreCase) && !routePair.UseOutputCaching)
                {
                    routePair.ControllerName = "DynamicRoute";
                }
                else if (routePair.ControllerName.Equals("DynamicRoute", StringComparison.InvariantCultureIgnoreCase) && routePair.UseOutputCaching)
                {
                    routePair.ControllerName = "DynamicRouteCached";
                }

                // Handle passing the Include In Output Cache
                switch (routePair.ControllerName.ToLower())
                {
                case "dynamicroute":
                case "dynamicroutecached":
                case "dynamicroutetemplate":
                    RequestArgs.CurrentRequestContext.RouteData.Values["IncludeDocumentInOutputCache"] = routePair.IncludeDocumentInOutputCache;
                    break;
                }

                // Setup routing with new values
                RequestArgs.CurrentRequestContext.RouteData.Values["Controller"] = routePair.ControllerName;
                RequestArgs.CurrentRequestContext.RouteData.Values["Action"]     = routePair.ActionName;

                foreach (string Key in routePair.RouteValues.Keys)
                {
                    RequestArgs.CurrentRequestContext.RouteData.Values[Key] = routePair.RouteValues[Key];
                }

                // Allow users to adjust the RequestContext further
                RequestRoutingHandler.FinishEvent();

                // Pass back context
                RequestContext = RequestArgs.CurrentRequestContext;
            }

            IControllerFactory factory    = ControllerBuilder.Current.GetControllerFactory();
            IController        controller = factory.CreateController(RequestContext, routePair.ControllerName);

            controller.Execute(RequestContext);

            factory.ReleaseController(controller);
        }
Beispiel #2
0
        public static void OverrideRequestPageEvent(object sender, RequestRoutingEventArgs args)
        {
            var relativeUrl = (string)HttpContext.Current.Items["CurrentRelUrl"];

            HttpContext.Current.Items.Remove("CurrentRelUrl");
            var cultureCode = (string)HttpContext.Current.Items["CultureCode"];

            HttpContext.Current.Items.Remove("CultureCode");
            var urlMatchup = GetUrlMatch(relativeUrl, cultureCode);

            if (urlMatchup != null)
            {
                foreach (var item in urlMatchup.QueryStringPairs)
                {
                    args.CurrentRequestContext.RouteData.Values.Add(item.Key, item.Value);
                    //TODO: add these args to the ViewBag too for purposes of non controller page directs
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the page, and based on the Class of the Page, attempts to get the Dynamic routing information and processes.
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            var node = DynamicRouteHelper.GetPage();

            var routePair = ResolveRouteValues(node);

            RequestRoutingEventArgs RequestArgs = new RequestRoutingEventArgs()
            {
                Page                  = node,
                Configuration         = routePair,
                CurrentRequestContext = RequestContext
            };

            // Use event to allow users to overwrite the Dynamic Routing Data
            using (var RequestRoutingHandler = DynamicRoutingEvents.RequestRouting.StartEvent(RequestArgs))
            {
                // Setup routing with new values
                RequestArgs.CurrentRequestContext.RouteData.Values["Controller"] = routePair.ControllerName;
                RequestArgs.CurrentRequestContext.RouteData.Values["Action"]     = routePair.ActionName;
                foreach (string Key in routePair.RouteValues.Keys)
                {
                    RequestArgs.CurrentRequestContext.RouteData.Values[Key] = routePair.RouteValues[Key];
                }

                // Allow users to adjust the RequestContext further
                RequestRoutingHandler.FinishEvent();

                // Pass back context
                RequestContext = RequestArgs.CurrentRequestContext;
            }

            IControllerFactory factory    = ControllerBuilder.Current.GetControllerFactory();
            IController        controller = factory.CreateController(RequestContext, routePair.ControllerName);

            controller.Execute(RequestContext);

            factory.ReleaseController(controller);
        }