Ext.Net.HandlerMethods.GetHandlerMethods C# (CSharp) Method

GetHandlerMethods() private method

private GetHandlerMethods ( HttpContext context, string requestPath ) : HandlerMethods
context System.Web.HttpContext
requestPath string
return HandlerMethods
        public static HandlerMethods GetHandlerMethods(HttpContext context, string requestPath)
        {
            string path = VirtualPathUtility.ToAbsolute(requestPath);

            string cacheKey = HandlerMethods.CACHE_PREFIX + path;
            HandlerMethods handlerMethods = null;
            
            if (!IsDebugging)
            {
                handlerMethods = context.Cache[cacheKey] as HandlerMethods;
            }

            if (handlerMethods == null)
            {
                try
                {
                    Type requestedType = BuildManager.GetCompiledType(path);

                    if (requestedType == null)
                    {
                        requestedType = BuildManager.CreateInstanceFromVirtualPath(path, typeof(System.Web.UI.Page)).GetType();
                    }
                    handlerMethods = new HandlerMethods(requestedType);

                    if (!IsDebugging)
                    {
                        PutToCache(path, context, cacheKey, handlerMethods);
                    }
                }
                catch (System.Web.HttpException e)
                {
                    if (!requestPath.EndsWith(".aspx", true, CultureInfo.InvariantCulture))
                    {
                        return HandlerMethods.GetHandlerMethods(context, requestPath + "default.aspx");
                    }

                    throw e;
                }
            }

            return handlerMethods;
        }

Usage Example

        public void ProcessRequest(HttpContext context)
        {
            DirectResponse responseObject = new DirectResponse(true);

            try
            {
                HandlerMethods handler    = HandlerMethods.GetHandlerMethods(context, context.Request.FilePath);
                string         methodName = HandlerMethods.GetMethodName(context);

                if (handler == null)
                {
                    throw new Exception("The Method '{0}' has not been defined.".FormatWith(context.Request.FilePath));
                }

                if (methodName.IsEmpty())
                {
                    throw new Exception("No methodName has been set in the configuration.");
                }

                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(methodName));
                }

                responseObject.Result = directMethod.Invoke();
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(context))
                {
                    throw e;
                }

                responseObject.Success      = false;
                responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message;
            }

            context.Response.Cache.SetNoServerCaching();
            context.Response.Cache.SetMaxAge(TimeSpan.Zero);
            context.Response.Write(responseObject.ToString());
            context.Response.End();
        }
All Usage Examples Of Ext.Net.HandlerMethods::GetHandlerMethods