Пример #1
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();
        }
Пример #2
0
        void Application_Error(object sender, EventArgs e)
        {
            HttpApplication app     = sender as HttpApplication;
            HttpContext     context = app.Context;

            if (Ext.HasXCooliteHeader(context.Request))
            {
                AjaxResponse responseObject = new AjaxResponse(true);
                string       error          = null;
                if (HttpContext.Current != null)
                {
                    error = HttpContext.Current.Error != null?HttpContext.Current.Error.ToString() : null;
                }

                if (!ScriptManager.AjaxSuccess || !string.IsNullOrEmpty(error))
                {
                    responseObject.Success = false;
                    if (!string.IsNullOrEmpty(error))
                    {
                        responseObject.ErrorMessage = error;
                    }
                    else
                    {
                        responseObject.ErrorMessage = ScriptManager.AjaxErrorMessage;
                    }
                }

                app.Context.Response.Clear();
                app.Context.Response.ClearContent();
                app.Context.Response.ClearHeaders();
                app.Context.Response.StatusCode = (int)HttpStatusCode.OK;
                app.Context.Response.Write(responseObject.ToString());
                app.Context.Response.End();
                app.CompleteRequest();
            }
        }
Пример #3
0
        public override void Flush()
        {
            if (this.html.ToString().StartsWith("<Coolite.ManualAjaxResponse>"))
            {
                string script = StringUtils.LeftOf(StringUtils.RightOf(this.html.ToString(), "<Coolite.ManualAjaxResponse>"), "</Coolite.ManualAjaxResponse>");
                byte[] rsp    = System.Text.Encoding.UTF8.GetBytes(script);
                this.response.Write(rsp, 0, rsp.Length);
                this.response.Flush();
                return;
            }

            AjaxResponse ajaxResponse = new AjaxResponse(true);
            HttpContext  context      = HttpContext.Current;

            string error = context == null ? null : (context.Error != null ? context.Error.ToString() : null);

            if (!ScriptManager.AjaxSuccess || !string.IsNullOrEmpty(error))
            {
                ajaxResponse.Success = false;
                if (!string.IsNullOrEmpty(error))
                {
                    ajaxResponse.ErrorMessage = error;
                }
                else
                {
                    ajaxResponse.ErrorMessage = ScriptManager.AjaxErrorMessage;
                }
            }
            else
            {
                if (ScriptManager.ReturnViewState)
                {
                    ajaxResponse.ViewState          = AjaxRequestFilter.GetHiddenInputValue(this.html.ToString(), VIEWSTATE);
                    ajaxResponse.ViewStateEncrypted = AjaxRequestFilter.GetHiddenInputValue(this.html.ToString(), VIEWSTATEENCRYPTED);
                    ajaxResponse.EventValidation    = AjaxRequestFilter.GetHiddenInputValue(this.html.ToString(), EVENTVALIDATION);
                }

                object o = ScriptManager.ServiceResponse;

                if (o is Response)
                {
                    ajaxResponse.ServiceResponse = new ClientConfig().Serialize(o);
                }
                else
                {
                    ajaxResponse.ServiceResponse = o != null?JSON.Serialize(o) : null;
                }

                if (ScriptManager.ExtraParamsResponse.Count > 0)
                {
                    ajaxResponse.ExtraParamsResponse = ScriptManager.ExtraParamsResponse.ToJson();
                }

                if (ScriptManager.AjaxMethodResult != null)
                {
                    ajaxResponse.Result = ScriptManager.AjaxMethodResult;
                }

                string script = StringUtils.LeftOf(StringUtils.RightOf(this.html.ToString(), "<Coolite.AjaxResponse>"), "</Coolite.AjaxResponse>");
                if (!string.IsNullOrEmpty(script))
                {
                    ajaxResponse.Script = string.Concat("<string>", script);
                }
            }

            bool isUpload = context != null && Ext.HasInputFieldMarker(context.Request);

            byte[] data = System.Text.Encoding.UTF8.GetBytes((isUpload ? "<textarea>":"") + ajaxResponse.ToString() + (isUpload ? "</textarea>":""));
            this.response.Write(data, 0, data.Length);
            this.response.Flush();
        }