Пример #1
0
        private void ProcessRequest(HttpApplication app, HttpRequest request)
        {
            AjaxResponse responseObject = new AjaxResponse(true);

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

                if (handler == null)
                {
                    throw new Exception(string.Format("The Method '{0}' has not been defined.", request.FilePath));
                }

                if (string.IsNullOrEmpty(methodName))
                {
                    return;

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

                AjaxMethod ajaxMethod = handler.GetStaticMethod(methodName);

                if (ajaxMethod == null)
                {
                    throw new Exception(string.Format("The static AjaxMethod '{0}' has not been defined.", ajaxMethod));
                }

                object result = ajaxMethod.Invoke();

                if (!ScriptManager.AjaxSuccess)
                {
                    responseObject.Success      = false;
                    responseObject.ErrorMessage = ScriptManager.AjaxErrorMessage;
                }
                else
                {
                    responseObject.Result = result;
                }
            }
            catch (Exception e)
            {
                responseObject.Success      = false;
                responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message;
            }

            app.Context.Response.Clear();
            app.Context.Response.ClearContent();
            app.Context.Response.ClearHeaders();
            app.Context.Response.StatusCode  = 200;
            app.Context.Response.ContentType = "application/json";
            app.Context.Response.Charset     = "utf-8";
            app.Context.Response.Cache.SetNoServerCaching();
            app.Context.Response.Cache.SetMaxAge(TimeSpan.Zero);
            app.Context.Response.Write(responseObject.ToString());
            app.CompleteRequest();
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            AjaxResponse responseObject = new AjaxResponse(true);

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

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

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

                AjaxMethod ajaxMethod = handler.GetStaticMethod(methodName);

                if (ajaxMethod == null)
                {
                    throw new Exception(string.Format("The static AjaxMethod '{0}' has not been defined.", methodName));
                }

                responseObject.Result = ajaxMethod.Invoke();
            }
            catch (Exception 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();
        }