Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            //验证路径是否为请求普通资源
            if (context.Request.RawUrl.EndsWith(".aspx"))
            {
                PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
                IHttpHandler       handler = factory.GetHandler(context, context.Request.RequestType, context.Request.Url.AbsolutePath, context.Request.PhysicalApplicationPath);
                handler.ProcessRequest(context);
            }
            string requestPath = context.Request.Path;                  //请求路径
            string vPath       = UrlHelper.GetRealVirtualPath(context); //去除虚拟目录后得到的请求路径

            //尝试根据请求路径获取Action
            InvokeInfo vkInfo = InitEngine.GetInvokeInfo(vPath);

            if (vkInfo == null)
            {
                HttpContext.Current.Response.StatusCode = 404;
                HttpContext.Current.Response.Write("无法找到页面:" + context.Request.RawUrl);
            }
            else
            {
                string code = ValidateProcess(context, vkInfo);
                switch (code)
                {
                case "200":
                    //执行aop
                    if (vkInfo.Controller.Injector != null)
                    {
                        vkInfo.Controller.ControllerContext = context;
                        vkInfo.Controller.Injector.OnControllerExecuting(vkInfo.Controller);
                    }
                    ActionHandler.CreateHandler(vkInfo).ProcessRequest(context);
                    break;

                case "403":
                    HttpContext.Current.Response.StatusCode = 403;
                    HttpContext.Current.Response.Write("权限不足");
                    break;

                case "404":
                    HttpContext.Current.Response.StatusCode = 404;
                    HttpContext.Current.Response.Write("无法找到页面:" + context.Request.RawUrl);
                    break;

                default:
                    break;
                }
            }
        }