Пример #1
0
        private void RedirectPreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpApplication app     = sender as HttpApplication;
            HttpContext     context = app.Context;

            if (context.Response.StatusCode == 302)
            {
                if (Ext.HasXCooliteHeader(context.Request) || Ext.HasInputFieldMarker(context.Request))
                {
                    string url = context.Response.RedirectLocation;
                    context.Response.StatusCode      = 200;
                    context.Response.SuppressContent = false;
                    //context.Response.ContentType = "application/json";
                    context.Response.ContentType = "text/html";
                    context.Response.Charset     = "utf-8";
                    context.Response.ClearContent();

                    AjaxResponse responseObject = new AjaxResponse(true);

                    responseObject.Script = string.Concat("window.location=\"", url, "\";");

                    TextWriter writer = context.Response.Output;
                    writer.Write(responseObject.ToString());
                }
            }
        }
Пример #2
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();
        }
Пример #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();
        }
Пример #4
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();
            }
        }
Пример #5
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();
        }