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");
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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));
     };
 }
Esempio n. 4
0
 public IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
     return new MvcHandler(requestContext);
 }
Esempio n. 5
0
 public MvcHandler(RequestContext requestContext)
 {
     this.RequestContext = requestContext;
 }