public IController CreateController(RequestContext context, string controllerName)
 {
     string typeName = controllerName + "Controller";
     List<string> namespaces = new List<string>();
     namespaces.AddRange(context.RouteData.Namespaces);
     namespaces.AddRange(ControllerBuilder.Current.DefaultNamespaces);
     foreach (string ns in namespaces)
     {
         string controllTypeName = string.Format("{0}.{1}", ns, typeName);
         Type controllerType = null;
         foreach (Type type in controllerTypes)
         {
             if (string.Compare(type.FullName, controllTypeName, true) == 0)
             {
                 controllerType = type;
                 break;
             }
         }
         if (null != controllerType)
         {
             return (IController)Activator.CreateInstance(controllerType);
         }
     }
     return null;
 }
Example #2
0
        public void Execute(RequestContext context)
        {
            ControllerContext controllerContext = new ControllerContext();
            controllerContext.RequestContext = context;
            controllerContext.Controller = this;

            string actionName = context.RouteData.ActionName;
            this.ActionInvoker.InvokeAction(controllerContext, actionName);
        }
        public bool IsMatch(RewriteContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            try
            {
                if (IsDynamicMapping)
                {
                    RouteTable.Routes.Add("default", new Route { Url = "{controller}/{action}" });
                    ControllerBuilder.Current.SetControllerFactory(new DefaultControllerFactory());
                    ControllerBuilder.Current.DefaultNamespaces.Add("KyCMS.Web");

                    RouteData routeData = RouteTable.Routes.GetRouteData(HttpContext.Current);
                    if (null == routeData)
                    {
                        return false;
                    }
                    RequestContext requestContext = new RequestContext { RouteData = routeData, HttpContext = HttpContext.Current };
                    IHttpHandler handler = routeData.RouteHandler.GetHttpHandler(requestContext);
                    HttpContext.Current.RemapHandler(handler);

                    //System.Web.HttpContext.Current.Response.Write(System.Web.HttpContext.Current.Request.Url + "<br/>");
                    //System.Web.HttpContext.Current.Response.Write(context.Method + "<br/>");
                    //System.Web.HttpContext.Current.Response.Write(context.Location + "<br/>");
                    //System.Web.HttpContext.Current.Response.Write(context.MapPath(context.Expand(context.Location)) + "<br/>");
                }
                /*
                string filename = context.MapPath(context.Expand(_location));
                return File.Exists(filename) || Directory.Exists(filename);
                */
                return IsDynamicMapping;
            }
            catch
            {
                return false;
            }
        }
Example #4
0
 public MvcHandler(RequestContext context)
 {
     this.RequestContext = context;
 }
Example #5
0
 public IHttpHandler GetHttpHandler(RequestContext context)
 {
     return new MvcHandler(context);
 }