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

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

                    DirectResponse responseObject = new DirectResponse(true);

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

                    TextWriter writer = context.Response.Output;
                    writer.Write(responseObject.ToString());
                }
            }
        }
Пример #2
0
        public DirectResponse SayHello1(string name)
        {
            DirectResponse response = new DirectResponse();
            
            // Return a script to be executed on the client
            response.Script = string.Concat("alert('Hello, ", name, "');");

            return response;
        }
Пример #3
0
        public DirectResponse SayHello2(string name)
        {
            DirectResponse response = new DirectResponse();
            
            ParameterCollection parameters = new ParameterCollection();

            parameters["Greeting"] = "Hello, " + name;
            
            response.ExtraParamsResponse = parameters.ToJson();

            return response;
        }
Пример #4
0
        public void ProcessRequest(HttpContext context)
        {
            DirectResponse responseObject = new DirectResponse(true);

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

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

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

                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(methodName));
                }

                responseObject.Result = directMethod.Invoke();
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(context))
                {
                    throw 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();
        }
        public void ProcessRequest(HttpContext context)
        {
            DirectResponse responseObject = new DirectResponse(true);

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

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

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

                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(methodName));
                }

                responseObject.Result = directMethod.Invoke();
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(context))
                {
                    throw 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();
        }
Пример #6
0
        void Application_Error(object sender, EventArgs e)
        {
            HttpApplication app     = sender as HttpApplication;
            HttpContext     context = app.Context;

            if (RequestManager.HasXHeader(context.Request))
            {
                DirectResponse responseObject = new DirectResponse(true);
                string         error          = null;

                if (HttpContext.Current != null)
                {
                    error = HttpContext.Current.Error != null?HttpContext.Current.Error.ToString() : null;
                }

                if (!ResourceManager.AjaxSuccess || error.IsNotEmpty())
                {
                    responseObject.Success = false;

                    if (error.IsNotEmpty())
                    {
                        responseObject.ErrorMessage = error;
                    }
                    else
                    {
                        responseObject.ErrorMessage = ResourceManager.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();
            }
        }
Пример #7
0
        void Application_Error(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;
            HttpContext context = app.Context;

            if (RequestManager.HasXHeader(context.Request))
            {
                DirectResponse responseObject = new DirectResponse(true);
                string error = null;

                if (HttpContext.Current != null)
                {
                    error = HttpContext.Current.Error != null ? HttpContext.Current.Error.ToString() : null;    
                }
                
                if (!ResourceManager.AjaxSuccess || error.IsNotEmpty())
                {
                    responseObject.Success = false;

                    if (error.IsNotEmpty())
                    {
                        responseObject.ErrorMessage = error;
                    }
                    else
                    {
                        responseObject.ErrorMessage = ResourceManager.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();
            }
        }
Пример #8
0
        private void ProcessRequest(HttpApplication app, HttpRequest request)
        {
            DirectResponse responseObject = new DirectResponse(true);

            try
            {
                HttpContext context = HttpContext.Current;

                // Get handler
                HandlerMethods handler = HandlerMethods.GetHandlerMethods(context, request.FilePath);

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

                // Get method name to invoke
                string methodName = HandlerMethods.GetMethodName(context);

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


                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(directMethod));
                }

                object result = directMethod.Invoke();

                if (!ResourceManager.AjaxSuccess)
                {
                    responseObject.Success      = false;
                    responseObject.ErrorMessage = ResourceManager.AjaxErrorMessage;
                }
                else
                {
                    responseObject.Result = result;
                    responseObject.Script = ResourceManager.GetInstanceScript();
                }
            }
            catch (TargetInvocationException e)
            {
                if (HandlerMethods.RethrowException(HttpContext.Current))
                {
                    throw;
                }

                responseObject.Success      = false;
                responseObject.ErrorMessage = IsDebugging ? e.InnerException.ToString() : e.InnerException.Message;
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(HttpContext.Current))
                {
                    throw;
                }

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

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

                    DirectResponse responseObject = new DirectResponse(true);

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

                    TextWriter writer = context.Response.Output;
                    writer.Write(responseObject.ToString());
                }
            }
        }
Пример #10
0
        private void ProcessRequest(HttpApplication app, HttpRequest request)
        {
            DirectResponse responseObject = new DirectResponse(true);

            try
            {
                HttpContext context = HttpContext.Current;
                
                // Get handler
                HandlerMethods handler = HandlerMethods.GetHandlerMethods(context, request.FilePath);

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

                // Get method name to invoke
                string methodName = HandlerMethods.GetMethodName(context);

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


                DirectMethod directMethod = handler.GetStaticMethod(methodName);

                if (directMethod == null)
                {
                    throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(directMethod));
                }

                object result = directMethod.Invoke();

                if (!ResourceManager.AjaxSuccess)
                {
                    responseObject.Success = false;
                    responseObject.ErrorMessage = ResourceManager.AjaxErrorMessage;
                }
                else
                {
                    responseObject.Result = result;
                    responseObject.Script = ResourceManager.GetInstanceScript();
                }
            }
            catch (Exception e)
            {
                if (HandlerMethods.RethrowException(HttpContext.Current))
                {
                    throw 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();
        }
Пример #11
0
        public override void Flush()
        {
            string raw = this.html.ToString();

            StringBuilder buffer = new StringBuilder(256);

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

            object isUpdate = context.Items["Ext.Net.Direct.Update"];

            if (isUpdate != null && (bool)isUpdate)
            {
                this.ExtractUpdates(raw, buffer);
            }

            string dynamicHtml = this.ExtractDynamicHtml(raw);

            object isManual = context.Items["Ext.Net.Direct.Response.Manual"];

            if (isManual != null && (bool)isManual)
            {
                if (raw.StartsWith("<Ext.Net.Direct.Response.Manual>"))
                {
                    string script = dynamicHtml.ConcatWith(raw.RightOf("<Ext.Net.Direct.Response.Manual>").LeftOf("</Ext.Net.Direct.Response.Manual>"));
                    byte[] rsp    = System.Text.Encoding.UTF8.GetBytes(script);
                    this.response.Write(rsp, 0, rsp.Length);
                    this.response.Flush();
                    return;
                }
            }

            buffer.Append(dynamicHtml);

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

            if (!ResourceManager.AjaxSuccess || error.IsNotEmpty())
            {
                ajaxResponse.Success = false;

                if (error.IsNotEmpty())
                {
                    ajaxResponse.ErrorMessage = error;
                }
                else
                {
                    ajaxResponse.ErrorMessage = ResourceManager.AjaxErrorMessage;
                }
            }
            else
            {
                if (ResourceManager.ReturnViewState)
                {
                    ajaxResponse.ViewState          = AjaxRequestFilter.GetHiddenInputValue(raw, BaseFilter.VIEWSTATE);
                    ajaxResponse.ViewStateEncrypted = AjaxRequestFilter.GetHiddenInputValue(raw, BaseFilter.VIEWSTATEENCRYPTED);
                    ajaxResponse.EventValidation    = AjaxRequestFilter.GetHiddenInputValue(raw, BaseFilter.EVENTVALIDATION);
                }

                object obj = ResourceManager.ServiceResponse;

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

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

                if (ResourceManager.DirectMethodResult != null)
                {
                    ajaxResponse.Result = ResourceManager.DirectMethodResult;
                }

                buffer.Append(raw.RightOf("<Ext.Net.Direct.Response>").LeftOf("</Ext.Net.Direct.Response>"));

                if (buffer.Length > 0)
                {
                    ajaxResponse.Script = "<string>".ConcatWith(buffer.ToString());
                }
            }

            bool isUpload = context != null && RequestManager.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();
        }
Пример #12
0
        public override void Flush()
        {
            string raw = this.html.ToString();

            StringBuilder buffer = new StringBuilder(256);

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

            object isUpdate = context.Items["Ext.Net.Direct.Update"];

            if (isUpdate != null && (bool)isUpdate)
            {
                this.ExtractUpdates(raw, ref buffer);
            }

            string dynamicHtml = this.ExtractDynamicHtml(raw);

            object isManual = context.Items["Ext.Net.Direct.Response.Manual"];

            if (isManual != null && (bool)isManual)
            {
                if (raw.StartsWith("<Ext.Net.Direct.Response.Manual>"))
                {
                    string script = dynamicHtml.ConcatWith(raw.RightOf("<Ext.Net.Direct.Response.Manual>").LeftOf("</Ext.Net.Direct.Response.Manual>"));
                    byte[] rsp = System.Text.Encoding.UTF8.GetBytes(script);
                    this.response.Write(rsp, 0, rsp.Length);
                    this.response.Flush();
                    return;
                }
            }

            buffer.Append(dynamicHtml);

            string error = context == null ? null : (context.Error != null ? context.Error.ToString() : null);
            
            if (!ResourceManager.AjaxSuccess || error.IsNotEmpty())
            {
                ajaxResponse.Success = false;

                if (error.IsNotEmpty())
                {
                    ajaxResponse.ErrorMessage = error; 
                }
                else
                {
                    ajaxResponse.ErrorMessage = ResourceManager.AjaxErrorMessage; 
                }
            }
            else
            {
                if (ResourceManager.ReturnViewState)
                {
                    ajaxResponse.ViewState = AjaxRequestFilter.GetHiddenInputValue(raw, BaseFilter.VIEWSTATE);
                    ajaxResponse.ViewStateEncrypted = AjaxRequestFilter.GetHiddenInputValue(raw, BaseFilter.VIEWSTATEENCRYPTED);
                    ajaxResponse.EventValidation = AjaxRequestFilter.GetHiddenInputValue(raw, BaseFilter.EVENTVALIDATION);
                }

                object obj = ResourceManager.ServiceResponse;

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

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

                if (ResourceManager.DirectMethodResult != null)
                {
                    ajaxResponse.Result = ResourceManager.DirectMethodResult;
                }

                buffer.Append(raw.RightOf("<Ext.Net.Direct.Response>").LeftOf("</Ext.Net.Direct.Response>"));

                if (buffer.Length > 0)
                {
                    ajaxResponse.Script = "<string>".ConcatWith(buffer.ToString());
                }
            }

            bool isUpload = context != null && RequestManager.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();
        }