public ActionResult Lookup(string callsid, string pid) { var packageService = new PackageService(); Task<Package>.Factory.StartNew( p => packageService.LocatePackage(pid), new Dictionary<string, string>() { { "CallSid", callsid }, { "FoundRedirectUrl", Url.Action("Complete", null, null, Request.Url.Scheme) }, { "NotFoundRedirectUrl", Url.Action("NotFound", null, null, Request.Url.Scheme) }, { "ErrorRedirectUrl", Url.Action("Error", null, null, Request.Url.Scheme) } }, CancellationToken.None ).ContinueWith(t => { Dictionary<string, string> state = (Dictionary<string, string>)t.AsyncState; if (t.IsCanceled || t.IsFaulted) { RedirectCall(state["CallSid"], state["ErrorRedirectUrl"]); } if (t.Result == null) { RedirectCall(state["CallSid"], state["NotFoundRedirectUrl"]); } else { string url = string.Format("{0}?s={1}", state["FoundRedirectUrl"], t.Result.Status); RedirectCall(state["CallSid"], url); } return; } ); var response = new TwilioResponse(); response.Play( Url.AbsoluteContent("~/Content/Audio/clocktickfast.mp3", Request.Url.AbsoluteUri), new { loop = "true" }); return TwiML(response); }