コード例 #1
0
        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");
        }
コード例 #2
0
ファイル: DefaultController.cs プロジェクト: keily/MvcRouting
 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);
 }
コード例 #3
0
ファイル: UrlRoutingModule.cs プロジェクト: proson/project
 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));
     };
 }
コード例 #4
0
ファイル: MvcRouteHandler.cs プロジェクト: keily/MvcRouting
 public IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
     return new MvcHandler(requestContext);
 }
コード例 #5
0
ファイル: MvcHandler.cs プロジェクト: keily/MvcRouting
 public MvcHandler(RequestContext requestContext)
 {
     this.RequestContext = requestContext;
 }