Ejemplo n.º 1
0
 /// <summary>
 /// 获取请求处理
 /// </summary>
 /// <param name="context"></param>
 /// <param name="requestType"></param>
 /// <param name="url"></param>
 /// <param name="pathTranslated"></param>
 /// <returns></returns>
 public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
 {
     //验证路径是否为请求普通资源
     if (url.EndsWith(".aspx"))
     {
         PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
         IHttpHandler       handler = factory.GetHandler(context, requestType, url, pathTranslated);
         return(handler);
     }
     else
     {
         string requestPath = context.Request.Path;                  //请求路径
         string vPath       = UrlHelper.GetRealVirtualPath(context); //去除虚拟目录后得到的请求路径
         //尝试根据请求路径获取Action
         InvokeInfo vkInfo = InitEngine.GetInvokeInfo(vPath);
         if (vkInfo == null)
         {
             ExceptionHelper.Throw404Exception(context);
         }
         if (vkInfo.Action.Attr != null && !vkInfo.Action.Attr.AllowExecute(context.Request.HttpMethod)) //限定谓词
         {
             ExceptionHelper.Throw403Exception(context);
         }
         return(ActionHandler.CreateHandler(vkInfo));
     }
 }
Ejemplo n.º 2
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;
                }
            }
        }