public IController CreateController(RequestContext requestContext, string controllerName) { RouteData routeData = requestContext.RouteData; string controllerType = string.Format("{0}Controller", controllerName); IController controller; controller = this.CreateControler(controllerType); if (null != controller) { return controller; } foreach (string assembly in routeData.Assemblies) { controller = this.CreateControler(controllerType, assembly); if (null != controller) { return controller; } foreach (string ns in routeData.Namespaces) { controllerType = string.Format("{0}.{1}Controller", ns, controllerName); controller = this.CreateControler(controllerType, assembly); if (null != controller) { return controller; } } } throw new InvalidOperationException("Cannot locate the controller"); }
public void Execute(RequestContext requestContext) { string action = requestContext.RouteData.Action; MethodInfo method = this.GetType().GetMethod(action); ActionResult result = (ActionResult)method.Invoke(this, null); ControllerContext controllerContext = new ControllerContext { RequestContext = requestContext }; result.ExecuteResult(controllerContext); }
public void Init(HttpApplication context) { context.PostResolveRequestCache += (sender, arge) => { HttpContextWrapper contextWrapper = new HttpContextWrapper(context.Context); HttpContextBase httpContext = contextWrapper; RouteData routeData = RouteTable.Routes.GetRouteData(httpContext); if (routeData == null) { return; } RequestContext requestContext = new RequestContext() { HttpContext = httpContext, RouteData = routeData }; httpContext.RemapHandler(routeData.RouteHandler.GetHttpHandler(requestContext)); }; }
public IHttpHandler GetHttpHandler(RequestContext requestContext) { return new MvcHandler(requestContext); }
public MvcHandler(RequestContext requestContext) { this.RequestContext = requestContext; }