public virtual ActionResult GetBundle() { var authenticationResult = AuthenticateUser(); if (authenticationResult != null) { return(authenticationResult); } var output = new JsonContentResultWriter(new StringWriter()); // run each bundle entry through the MVC pipeline foreach (var key in Request.Form.AllKeys) { if (string.IsNullOrEmpty(key)) { continue; } if (key == "username" || key == "password" || key == "domain") { continue; } var url = Request.Form[key]; var uri = new Uri(url, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) { uri = new Uri("http://127.0.0.1" + url); } // find the route var textWriter = new StringWriter(); var httpContext = new HttpContextWrapper(new HttpContext(new HttpRequest(string.Empty, uri.AbsoluteUri, uri.Query.Mid(1)), new HttpResponse(textWriter))); var routeData = RouteTable.Routes.GetRouteData(httpContext); if (routeData == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Route not found: " + url)); } // execute the controller var controllerName = routeData.Values["controller"].ToString(); var requestContext = new RequestContext(httpContext, routeData); var controller = ControllerBuilder.Current.GetControllerFactory().CreateController(requestContext, controllerName); controller.Execute(requestContext); // if empty - write an empty object var result = textWriter.ToString(); if (string.IsNullOrEmpty(result)) { output.WritePropertyName(key); output.WriteStartObject(); output.WriteEndObject(); continue; } JObject jObject; try { jObject = JObject.Parse(result); } catch { return(new HttpStatusCodeResult(HttpStatusCode.NotFound, result)); } output.WritePropertyName(key); jObject.WriteTo(output); } return(output.ToContentResult()); }