private static bool SendInvokeResult(HttpContext context, HttpRequest request, string typeName, string methodName, JsonResponseFormats format) { if (format == JsonResponseFormats.invalid) { throw new InvalidOperationException("The specified response format requested was invalid."); } string[] parameters = null; if (request.QueryString["params"] != null) { parameters = HttpUtility.UrlDecode(request.QueryString["params"]).Split(new string[] { ParameterDelimiter }, StringSplitOptions.RemoveEmptyEntries); List <string> newParameters = new List <string>(); foreach (string parameter in parameters) { // if for some strange reason someone enters this sequence of characters the javascript will reverse and replace the sequence // here we're un-reversing string reversed = StringExtensions.Reverse(ParameterDelimiter); newParameters.Add(parameter.Replace(reversed, ParameterDelimiter)); } parameters = newParameters.ToArray(); } HttpResponse response = context.Response; JsonResult result = GetJsonResultFromInvoke(typeName, methodName, parameters); switch (format) { case JsonResponseFormats.json: response.Clear(); response.Write(JsonSerializer.ToJson(result)); response.Flush(); response.SuppressContent = true; // necessary to suppress html that may have been added to the response. //HttpContext.Current.ApplicationInstance.CompleteRequest(); //response.End(); break; case JsonResponseFormats.box: BoxServer.SendDataBoxResponse(context, result); break; } return(true); }
public static bool ProcessRequest(HttpContext context) { HttpRequest request = context.Request; try { if (context == null) { throw NewInvalidOperationException(); } Resources.Load(Assembly.GetExecutingAssembly()); if (IsProviderInfoRequest(request)) { return(SendProviderInfo(context)); } if (IsInitRequest(request)) { // is this an init request // ?init={typename}&varname={clientInstanceName} string initType = request.QueryString["t"]; string varname = request.QueryString["varname"]; if (!string.IsNullOrEmpty(initType) && !string.IsNullOrEmpty(varname)) { return(SendClientInstantiationScript(context, initType, varname)); } } // this is a resource script request // this component doesn't use the standard axd style resource loading // mechanism. string scriptName; if (IsResourceScriptRequest(request, out scriptName)) { return(SendRequestedScript(context, scriptName)); } if (IsInvokeRequest(request)) { JsonResponseFormats format = JsonResponseFormats.invalid; // is this an invoke request // ?t={type}&m={method}¶ms={delimited} string typeName = request.QueryString["t"]; string methodName = request.QueryString["m"]; string formatString = request.QueryString["f"]; if (!string.IsNullOrEmpty(formatString)) { EnumExtensions.TryParseAs <JsonResponseFormats>(formatString, out format); } if (format == JsonResponseFormats.invalid) { format = JsonResponseFormats.json; } if (!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(methodName)) { return(SendInvokeResult(context, request, typeName, methodName, format)); } } string boxPath; if (IsBoxRequest(request, out boxPath)) { SendBoxResponse(context, boxPath); return(true); } if (IsDataBoxScriptRequest(request)) { SendDataBoxScriptResponse(context); return(true); } } catch (Exception ex) { string url = request.Url.PathAndQuery; Logging.LogManager.CurrentLog.AddEntry("An error of type ({0}) occurred processing javascript request: {1}", ex, new string[] { ex.GetType().Name, url }); } return(false); }