Example #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());
                }
            }
        }
Example #2
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();
        }