Beispiel #1
0
        private void InvokeClass(HttpContext context)
        {
            Type t = null;

            //ViewController是由页面的前两个路径决定了。
            string[] items     = QueryTool.GetLocalPath(context.Request.Url).Trim('/').Split('/');
            string   className = Const.Default;

            if (RouteConfig.RouteMode == 1)
            {
                className = items.Length > 2 ? items[0] + "." + items[1] : items[0];
            }
            else if (RouteConfig.RouteMode == 2)
            {
                className = items.Length > 1 ? items[0] + "." + items[1] : items[0];
            }
            t = ControllerCollector.GetController(className);
            if (t == null || t.Name == Const.DefaultController)
            {
                if (MicroService.Run.Proxy(context, false))//客户端做为网关。
                {
                    return;
                }
            }
            if (t == null)
            {
                WriteError("You need a " + className + " controller for coding!", context);
            }
            else
            {
                try
                {
                    object o = Activator.CreateInstance(t);//实例化
                    t.GetMethod("ProcessRequest").Invoke(o, new object[] { context });
                }

                catch (ThreadAbortException e)
                {
                    //内部提前Response.End()时引发的异常
                    //ASP.NET 的机制就是通过异常退出线程(不要觉的奇怪)
                }
                catch (Exception err)
                {
                    WriteError(err.Message, context);
                }
            }
            //context.Response.End();
        }
Beispiel #2
0
 private static Type GetController(string name)
 {
     return(ControllerCollector.GetController(name));
 }