public IEnumerable<ICoroutineResult> Handle(IHttpContext context, IResponse response, object viewBag)
		{
			var viewResponse = (ViewResponse)response;
			var view = viewResponse.View ?? context.RouteParams["action"].ToString();
			
			if (view.StartsWith("~"))
			{
				view = view.TrimStart('~');
			}
			else
			{
				var viewsRoot = _mvcModule.GetParameter<string>("views").TrimStart('~').TrimStart('/');
				viewsRoot = viewsRoot.Replace("{controller}", context.RouteParams["controller"].ToString());
				viewsRoot = viewsRoot.Replace("{action}", view.Trim('/'));
				if (context.RouteParams.ContainsKey("area"))
				{
					viewsRoot = viewsRoot.Replace("{area}", context.RouteParams["area"].ToString());
				}
				view = "/" + viewsRoot.Trim('/');
				view = view.TrimStart('~');
			}

			if (!view.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase))
			{
				view += ".cshtml";
			}
			var wrappedContext = new WrappedHttpContext(context);
			var wrappedRequest = (IHttpRequest)wrappedContext.Request;
			wrappedRequest.SetInputStream(context.Request.InputStream);
			wrappedRequest.SetUrl(new Uri(view,UriKind.RelativeOrAbsolute));
			var wrappedResponse = (IHttpResponse)wrappedContext.Response;
			wrappedResponse.SetOutputStream(context.Response.OutputStream);
			yield return _httpModule.ExecuteRequestInternal(wrappedContext, viewResponse.Model, new ModelStateDictionary(), viewBag);
		}
		public IEnumerable<ICoroutineResult> RenderLayout(string name, IHttpContext mainContext, dynamic viewBag)
		{
			var http = ServiceLocator.Locator.Resolve<HttpModule>();

			var context = new WrappedHttpContext(mainContext);

			var newUrl = name.TrimStart('~');

			((IHttpRequest)context.Request).SetUrl(new Uri(newUrl, UriKind.Relative));
			((IHttpRequest)context.Request).SetQueryString(mainContext.Request.QueryString);
			var internalCoroutine = http.SetupInternalRequestCoroutine(context, null, viewBag);


			yield return CoroutineResult.RunCoroutine(internalCoroutine)
				.WithTimeout(TimeSpan.FromMinutes(1))
				.AndWait();
			/*Exception problem = null;
			Action<Exception> onError = (Action<Exception>)(ex => problem = ex);
			((ICoroutinesManager)_createMethod.Invoke((object)null, new object[0])).StartCoroutine(internalCoroutine, onError);

			ManualResetEventSlim waitSlim = new ManualResetEventSlim(false);
			while (4L > (long)internalCoroutine.Status)
				waitSlim.Wait(10);
			while (!RunningStatusExtension.Is(internalCoroutine.Status, RunningStatus.NotRunning))
				waitSlim.Wait(10);
			if (problem != null)
				throw new Exception("Error running subtask", problem);*/
			//task.Wait();
			var stream = context.Response.OutputStream as MemoryStream;

			// ReSharper disable once PossibleNullReferenceException
			//r result = Encoding.UTF8.GetString(stream.ToArray());
			stream.Seek(0, SeekOrigin.Begin);
			var bytes = stream.ToArray();
			yield return CoroutineResult.Return(bytes);
			//rn new BufferItem { Value = result };
		}
		public RawString RenderPage(string name, object model = null, bool skipLayout = false)
		{
			var http = ServiceLocator.Locator.Resolve<HttpModule>();

			var context = new WrappedHttpContext(Context);

			var newUrl = name.TrimStart('~');

			((IHttpRequest)context.Request).SetUrl(new Uri(newUrl, UriKind.Relative));
			((IHttpRequest)context.Request).SetQueryString(Context.Request.QueryString);
			var internalCoroutine = http.SetupInternalRequestCoroutine(context, model, ViewBag);
			Exception problem = null;
			Action<Exception> onError = (Action<Exception>)(ex => problem = ex);
			((ICoroutinesManager)_createMethod.Invoke((object)null, new object[0])).StartCoroutine(internalCoroutine, onError);

			ManualResetEventSlim waitSlim = new ManualResetEventSlim(false);
			while (4L > (long)internalCoroutine.Status)
				waitSlim.Wait(10);
			while (!RunningStatusExtension.Is(internalCoroutine.Status, RunningStatus.NotRunning))
				waitSlim.Wait(10);
			if (problem != null)
				throw new Exception("Error running subtask", problem);
			/*var task = CoroutineResult.WaitForCoroutine(internalCoroutine);
			//task.Wait();*/
			var stream = context.Response.OutputStream as MemoryStream;

			// ReSharper disable once PossibleNullReferenceException
			var result = Encoding.UTF8.GetString(stream.ToArray());
			return new RawString(result);
		}