Пример #1
0
        /// <summary>
        /// 通过实现 IHttpHandler 接口的自定义 HttpHandler 启用 HTTP Web 请求的处理。
        /// </summary>
        /// <param name="context">HttpContext 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。</param>
        public virtual void ProcessRequest(HttpContext context)
        {
            if (this.Config != null)
            {
                switch (this.Config.Action)
                {
                case "none":
                    this.SimplePath  = context.Request.Path;
                    this.RealPath    = context.Request.Path;
                    this.FilePath    = context.Request.Path;
                    this.PathInfo    = context.Request.PathInfo;
                    this.QueryString = context.Request.QueryString.ToString();
                    this.Url         = context.Request.Url.ToString();
                    break;

                case "redirect":
                    context.Response.Redirect(this.Url, true);
                    break;

                case "rewrite":
                    break;
                }
            }
            else
            {
                this.Config        = new viviapi.SysConfig.UrlManagerConfig();
                this.Config.Action = "none";
                this.SimplePath    = context.Request.Path;
                this.RealPath      = context.Request.Path;
                this.FilePath      = context.Request.Path;
                this.PathInfo      = context.Request.PathInfo;
                this.QueryString   = context.Request.QueryString.ToString();
                this.Url           = context.Request.Url.ToString();
            }
        }
Пример #2
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="context">HttpContext 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。</param>
 /// <param name="config">符合的配置项。</param>
 /// <param name="simplePath">相对于应用程序根目录的路径。</param>
 /// <param name="realPath">相对于应用程序根目录的实际需调用文件路径。</param>
 /// <param name="filePath">相对于应用程序根目录的静态文件路径。</param>
 /// <param name="pathInfo">源的附加路径信息。 </param>
 /// <param name="queryString">请求查询字符串。</param>
 /// <param name="url">重定向URL。</param>
 public StaticFileHandler(
     HttpContext context,
     viviapi.SysConfig.UrlManagerConfig config,
     string simplePath,
     string realPath,
     string filePath,
     string pathInfo,
     string queryString,
     string url) : base(context, config, simplePath, realPath, filePath, pathInfo, queryString, url)
 {
 }
Пример #3
0
        /// <summary>
        /// 返回实现 IHttpHandler 接口的类的实例。
        /// </summary>
        /// <param name="context">HttpContext 类的实例,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。</param>
        /// <param name="requestType">客户端使用的 HTTP 数据传输方法(GET 或 POST)。 </param>
        /// <param name="url">所请求资源的 RawUrl。</param>
        /// <param name="pathTranslated">所请求资源的 PhysicalApplicationPath。</param>
        /// <returns></returns>
        public System.Web.IHttpHandler GetHandler(System.Web.HttpContext context, string requestType, string url, string pathTranslated)
        {
//			context.Response.Write(requestType + "<BR>");
//			context.Response.Write(url + "<BR>");
//			context.Response.Write(pathTranslated + "<BR>");

            viviapi.SysConfig.UrlManagerConfig config = null;
            string simplePath  = string.Empty;
            string realPath    = string.Empty;
            string filePath    = string.Empty;
            string pathInfo    = string.Empty;
            string queryString = string.Empty;
            string redirectUrl = string.Empty;

            bool isMatch = viviapi.SysConfig.UrlManagerConfig.IsMatch(context, ref config, ref simplePath, ref realPath, ref filePath, ref pathInfo, ref queryString, ref redirectUrl);


//			context.Response.Write(isMatch.ToString());
//			context.Response.Write(simplePath + "<BR>");
//			context.Response.Write(realPath + "<BR>");
//			context.Response.Write(filePath + "<BR>");
//			context.Response.Write(queryString + "<BR>");

            if (config != null)
            {
//				context.Response.Write(config.Action + "<BR>");
//				context.Response.Write(config.Pattern + "<BR>");
//				context.Response.Write(config.RealPath + "<BR>");
//				context.Response.Write(config.FilePath + "<BR>");
//				context.Response.Write(config.QueryString + "<BR>");
//				context.Response.Write(config.PathInfo + "<BR>");

                if (System.IO.Path.GetExtension(context.Request.Path) == ".aspx")
                {
                    return(new PageHandler(context, config, simplePath, realPath, filePath, pathInfo, queryString, redirectUrl));
                }
                else
                {
                    return(new StaticFileHandler(context, config, simplePath, realPath, filePath, pathInfo, queryString, redirectUrl));
                }
            }
            if (System.IO.Path.GetExtension(context.Request.Path) == ".aspx")
            {
                return(new PageHandler());
            }
            else
            {
                return(new StaticFileHandler());
            }
        }
Пример #4
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="context">HttpContext 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。</param>
 /// <param name="config">符合的配置项。</param>
 /// <param name="simplePath">相对于应用程序根目录的路径。</param>
 /// <param name="realPath">相对于应用程序根目录的实际需调用文件路径。</param>
 /// <param name="filePath">相对于应用程序根目录的静态文件路径。</param>
 /// <param name="pathInfo">源的附加路径信息。 </param>
 /// <param name="queryString">请求查询字符串。</param>
 /// <param name="url">重定向URL。</param>
 public HandlerBase(
     HttpContext context,
     viviapi.SysConfig.UrlManagerConfig config,
     string simplePath,
     string realPath,
     string filePath,
     string pathInfo,
     string queryString,
     string url) : this()
 {
     this.Config      = config;
     this.SimplePath  = context.Request.ApplicationPath == "/" ? simplePath : context.Request.ApplicationPath + simplePath;
     this.RealPath    = context.Request.ApplicationPath == "/" ? realPath : context.Request.ApplicationPath + realPath;
     this.FilePath    = context.Request.ApplicationPath == "/" ? filePath : context.Request.ApplicationPath + filePath;
     this.PathInfo    = pathInfo;
     this.QueryString = queryString;
     this.Url         = url;
 }