Beispiel #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();
        }
Beispiel #2
0
        private void OnPostAcquireRequestState(object sender, EventArgs eventArgs)
        {
            HttpApplication app     = (HttpApplication)sender;
            HttpRequest     request = app.Context.Request;

            if (Ext.IsAjaxRequest)
            {
                if (AjaxMethod.IsStaticMethodRequest(request) || Coolite.Utilities.ReflectionUtils.IsTypeOf(app.Context.Handler, "System.Web.Script.Services.ScriptHandlerFactory+HandlerWrapper"))
                {
                    this.ProcessRequest(app, request);
                }
            }
        }
Beispiel #3
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();
        }