Beispiel #1
0
        public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            //得到编译实例(通过反射)
            PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
            IHttpHandler       handler = factory.GetHandler(context, requestType, url, pathTranslated);

            //过滤字符串
            if (requestType == "POST")
            {
                Page page = handler as Page;
                if (page != null && !context.Request.Url.ToString().Contains("ManageMessage.aspx") && !context.Request.Url.ToString().Contains("SetAgreement.aspx") && !context.Request.Url.ToString().Contains("SetAgreement2.aspx"))
                {
                    page.PreLoad += new EventHandler(FilterStrFactoryHandler_PreLoad);
                }
            }
            if (requestType == "GET")
            {
                Page page = handler as Page;
                if (page != null && !context.Request.Url.ToString().Contains("ManageMessage.aspx") && !context.Request.Url.ToString().Contains("SetAgreement.aspx") && !context.Request.Url.ToString().Contains("SetAgreement2.aspx"))
                {
                    page.PreLoad += new EventHandler(FilterStrFactoryHandler_PreLoad1);
                }
            }
            //返回
            return(handler);
        }
Beispiel #2
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));
     }
 }
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
            IHttpHandler       handler = factory.GetHandler(context, requestType, url, pathTranslated);

            //执行一些其它操作
            Execute(handler);

            return(handler);
        }
Beispiel #4
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;
                }
            }
        }
Beispiel #5
0
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);

            if (!IPAllowUtility.IpIsAllowed(context))
            {
                url = HttpContext.Current.Request.ApplicationPath + "error.aspx";
            }
            IHttpHandler handler;

            if (-1 == url.IndexOf(".rar"))
            {
                handler = factory.GetHandler(context, requestType, url, pathTranslated);
            }
            else
            {
                handler = null;
            }
            return(handler);
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="feature"></param>
        public override void Execute()
        {
            //if (this.Feature != null)
            //{
            //    //不加这句表单样式有问题
            //    HttpContext.Current.Response.Write("<!DOCTYPE html>\n");
            //    HttpContext.Current.Response.Write(this.Feature.ToAdjustWindowScriptBlock(true));
            //    HttpContext.Current.Response.Flush();
            //}

            PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(System.Web.UI.PageHandlerFactory), true);

            Uri url = new Uri(HttpContext.Current.Request.Url, this.NavigateUrl);

            IHttpHandler handler = factory.GetHandler(HttpContext.Current,
                                                      HttpContext.Current.Request.RequestType,
                                                      url.AbsolutePath, HttpContext.Current.Request.PhysicalApplicationPath);

            if (handler is Page)
            {
                HttpContext.Current.Items["transferTarget"] = AppendCurrentRequestParams(this.NavigateUrl);

                ((Page)handler).PreRenderComplete += new EventHandler(TransferCommand_PreRenderComplete);

                //add by zhouweihai 2008-09-02 页面加载PageModule
                WebUtility.AttachPageModules((Page)handler);
            }

            StringBuilder strB = new StringBuilder(10240);

            TextWriter tw = new StringWriter(strB);

            HttpContext.Current.Server.Execute(handler, tw, true);

            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }
        /// <summary />
        /// <remarks>https://stackoverflow.com/questions/9930880/call-the-default-asp-net-httphandler-from-a-custom-handler</remarks>
        public void ProcessRequest2(HttpContext context)
        {
            if (File.Exists(context.Request.MapPath(context.Request.FilePath)))
            {
                // the internal constructor doesn't do anything but prevent you from instantiating
                // the factory, so we can skip it.
                PageHandlerFactory factory =
                    (PageHandlerFactory)System.Runtime.Serialization.FormatterServices
                    .GetUninitializedObject(typeof(System.Web.UI.PageHandlerFactory));

                string newTarget   = "~/md_base.aspx";
                string queryString = context.Request.QueryString.ToString();

                // the 3rd parameter must be just the file name.
                // the 4th parameter should be the physical path to the file, though it also
                //   works fine if you pass an empty string - perhaps that's only to override
                //   the usual presentation based on the path?

                var handler = factory.GetHandler(context, "GET", newTarget,
                                                 context.Request.MapPath(newTarget));

                // Update the context object as it should appear to your page/app, and
                // assign your new handler.
                // context.RewritePath(newTarget, "", queryString);
                context.Handler = handler;

                // .. and done

                handler.ProcessRequest(context);
            }
            else
            {
                context.Response.StatusCode      = 404;
                context.Response.SuppressContent = true;
            }
        }