protected string RenderHtml(string controller, string action, BeeDataAdapter dataAdapter) { string result = string.Empty; using (MemoryStream memoryStream = new MemoryStream()) { using (StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.UTF8)) { HttpWorkerRequest wr = new System.Web.Hosting.SimpleWorkerRequest("index.htm", string.Empty, streamWriter); HttpContext httpContext = new HttpContext(wr); httpContext.Response.ContentEncoding = Encoding.Default; MvcDispatcher.ExecuteAction(httpContext, controller, action, dataAdapter); httpContext.Response.Flush(); streamWriter.Flush(); memoryStream.Position = 0; //using (StreamReader reader = new StreamReader(memoryStream, Encoding.UTF8)) //{ // result = reader.ReadToEnd(); //} result = Encoding.UTF8.GetString(memoryStream.ToArray()); } } return(result); }
static private void ProcessRequest(string page, string query, System.IO.TextWriter writer) { System.Web.Hosting.SimpleWorkerRequest worker = new System.Web.Hosting.SimpleWorkerRequest(page, query, writer); System.Web.HttpRuntime.ProcessRequest(worker); }
public static RequestContext CreateRequestContext(Uri url) { var appVPath = VirtualPathUtility.ToAppRelative(url.IsAbsoluteUri ? url.LocalPath : url.ToString()).Replace("~/", ""); var request = new System.Web.Hosting.SimpleWorkerRequest(appVPath, "", null); var httpContext = new HttpContextWrapper(new HttpContext(request)); var routeData = RouteTable.Routes.GetRouteData(httpContext); return new RequestContext(httpContext, routeData); }
public static RequestContext CreateRequestContext(Uri url) { var appVPath = VirtualPathUtility.ToAppRelative(url.IsAbsoluteUri ? url.LocalPath : url.ToString()).Replace("~/", ""); var request = new System.Web.Hosting.SimpleWorkerRequest(appVPath, "", null); var httpContext = new HttpContextWrapper(new HttpContext(request)); var routeData = RouteTable.Routes.GetRouteData(httpContext); return(new RequestContext(httpContext, routeData)); }
public void ProcessRequest(Uri url, System.IO.Stream stream) { string file = url.LocalPath.Trim('/'); using (var wt = new System.IO.StreamWriter(stream)) { System.Web.Hosting.SimpleWorkerRequest swr = new System.Web.Hosting.SimpleWorkerRequest(file, "", wt); System.Web.HttpRuntime.ProcessRequest(swr); } }
public void ProcessRequest(string page) { var request = new System.Web.Hosting.SimpleWorkerRequest (page, // page being requested null, // query System.Console.Out // output ); System.Web.HttpRuntime.ProcessRequest(request); }
public void ProcessRequest(string page) { var request = new System.Web.Hosting.SimpleWorkerRequest (page, // the page being requested null, // query - none in this case System.Console.Out // output - any TextWriter will do ); // this will emit the page output to Console.Out System.Web.HttpRuntime.ProcessRequest(request); }
/// <summary> /// Осуществляет имитацию того, что у приложения есть <see cref="System.Web.HttpContext"/>. /// Т.е. имитирует работу из web-окружения. /// </summary> private void EmulateWebEnvironment() { // Имитируем работу из web-приложения. var request = new System.Web.Hosting.SimpleWorkerRequest( string.Empty, string.Empty, string.Empty, string.Empty, new System.IO.StringWriter()); System.Web.Fakes.ShimHttpContext.CurrentGet = () => { return(new System.Web.HttpContext(request)); }; }
/// <summary> /// Create Http Context /// </summary> public static void CreateHttpContext() { if (System.Web.HttpContext.Current == null) { System.Threading.Thread.GetDomain().SetData(".hostingVirtualPath", System.Web.HttpRuntime.AppDomainAppVirtualPath); System.Threading.Thread.GetDomain().SetData(".hostingInstallDir", System.Web.HttpRuntime.AspInstallDirectory); System.IO.TextWriter tw = new System.IO.StringWriter(); System.Web.HttpWorkerRequest wr = new System.Web.Hosting.SimpleWorkerRequest("default.aspx", "", tw); System.Web.HttpContext.Current = new System.Web.HttpContext(wr); } }
protected StreamResult OutputPage(string fileName, string controller, string action) { MemoryStream memoryStream = new MemoryStream(); StreamWriter streamWriter = new StreamWriter(memoryStream); HttpWorkerRequest wr = new System.Web.Hosting.SimpleWorkerRequest("index.htm", string.Empty, streamWriter); HttpContext httpContext = new HttpContext(wr); httpContext.Response.ContentEncoding = Encoding.Default; MvcDispatcher.ExecuteAction(httpContext, controller, action, ViewData); httpContext.Response.Flush(); streamWriter.Flush(); StreamResult streamResult = new StreamResult(fileName, memoryStream); return(streamResult); }