private void ProcessRequestInit(HttpContextBase httpContext, out IController controller, out IControllerFactory factory)
        {
            // If request validation has already been enabled, make it lazy. This allows attributes like [HttpPost] (which looks
            // at Request.Form) to work correctly without triggering full validation.
            // Tolerate null HttpContext for testing.
            HttpContext currentContext = HttpContext.Current;

            if (currentContext != null)
            {
                bool?isRequestValidationEnabled = ValidationUtility.IsValidationEnabled(currentContext);
                if (isRequestValidationEnabled == true)
                {
                    ValidationUtility.EnableDynamicValidation(currentContext);
                }
            }

            AddVersionHeader(httpContext);
            RemoveOptionalRoutingParameters();

            // Get the controller type
            string controllerName = RequestContext.RouteData.GetRequiredString("controller");

            // Instantiate the controller and call Execute
            factory    = ControllerBuilder.GetControllerFactory();
            controller = factory.CreateController(RequestContext, controllerName);
            if (controller == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              MvcResources.ControllerBuilder_FactoryReturnedNull,
                              factory.GetType(),
                              controllerName));
            }
        }
        public virtual ModuleRequestResult ExecuteRequest(ModuleRequestContext context)
        {
            this.EnsureInitialized();
            this.RequestContext = this.RequestContext ?? new RequestContext(context.HttpContext, context.RouteData);
            var currentContext = HttpContext.Current;

            if (currentContext != null)
            {
                var isRequestValidationEnabled = ValidationUtility.IsValidationEnabled(currentContext);
                if (isRequestValidationEnabled == true)
                {
                    ValidationUtility.EnableDynamicValidation(currentContext);
                }
            }

            this.AddVersionHeader(this.RequestContext.HttpContext);
            this.RemoveOptionalRoutingParameters();

            var controllerName = this.RequestContext.RouteData.GetRequiredString("controller");

            // Construct the controller using the ControllerFactory
            var controller = this.ControllerFactory.CreateController(this.RequestContext, controllerName);

            try
            {
                // Check if the controller supports IDnnController
                var moduleController = controller as IDnnController;

                // If we couldn't adapt it, we fail.  We can't support IController implementations directly :(
                // Because we need to retrieve the ActionResult without executing it, IController won't cut it
                if (moduleController == null)
                {
                    throw new InvalidOperationException("Could Not Construct Controller");
                }

                moduleController.ValidateRequest = false;

                moduleController.DnnPage = context.DnnPage;

                moduleController.ModuleContext = context.ModuleContext;

                moduleController.LocalResourceFile = string.Format(
                    "~/DesktopModules/MVC/{0}/{1}/{2}.resx",
                    context.ModuleContext.Configuration.DesktopModule.FolderName,
                    Localization.LocalResourceDirectory,
                    controllerName);

                moduleController.ViewEngineCollectionEx = this.ViewEngines;

                // Execute the controller and capture the result
                // if our ActionFilter is executed after the ActionResult has triggered an Exception the filter
                // MUST explicitly flip the ExceptionHandled bit otherwise the view will not render
                moduleController.Execute(this.RequestContext);
                var result = moduleController.ResultOfLastExecute;

                // Return the final result
                return(new ModuleRequestResult
                {
                    ActionResult = result,
                    ControllerContext = moduleController.ControllerContext,
                    ModuleActions = moduleController.ModuleActions,
                    ModuleContext = context.ModuleContext,
                    ModuleApplication = this,
                });
            }
            finally
            {
                this.ControllerFactory.ReleaseController(controller);
            }
        }