예제 #1
0
        //----------------------------------------------
        // 解析和获取处理器
        //----------------------------------------------
        public static void HandlerHttpApiRequest(HttpContext context)
        {
            var    req     = context.Request;
            var    uri     = req.Url;
            var    url     = uri.AbsolutePath.ToLower();
            object handler = null;

            // 获取处理器对象
            if (url.StartsWith("/httpapi/"))
            {
                // 以 /HttpApi/Type/Method 方式调用
                var typeName = HttpApiHelper.GetRequestTypeName();
                handler = TryGetHandlerFromCache(typeName);
                if (handler == null)
                {
                    handler = TryCreateHandlerFromAssemblies(typeName);
                }
            }
            else
            {
                // 以 Page.aspx/Method 方式调用
                int n = url.LastIndexOf("/");
                url = url.Substring(0, n);
                Type type = WebHandlerParser.GetCompiledType(url, url, context);
                handler = Activator.CreateInstance(type);
            }


            // 调用处理器方法
            if (handler != null)
            {
                HttpApiHelper.ProcessRequest(context, handler);
                DisposeIfNeed(handler);
            }
        }
예제 #2
0
        public static Type GetCompiledType(HttpContext context, string virtualPath, string physicalPath)
        {
            WebHandlerParser parser = new WebHandlerParser(context, virtualPath, physicalPath);
            Type type = parser.GetCompiledTypeFromCache();
            if (type != null)
                return type;

            throw new HttpException(string.Format("File '{0}' is not a web handler.", virtualPath));
        }
예제 #3
0
            internal static Type GetCompiledType(string virtualPath, string physicalPath, HttpContext context)
            {
                var parser = new WebHandlerParser(context, virtualPath, physicalPath);

                return(parser.GetCompiledTypeFromCache());
            }