title: Calling async method in controller
body: <p>I have a controller with something like the following:</p>
  
  <pre><code>public MyController : Controller
  {
      public ActionResult DoSomething()
      {
          CallSomeMethodWhichDoesAsyncOperations();
          return Json(new { success = successful }, JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>
  
  <p>When calling my controller I get the following error:</p>
  
  <blockquote>
    <p>An asynchronous operation cannot be started at this time. Asynchronous operations
       may only be started within an asynchronous handler or module or during certain
       events in the Page lifecycle. If this exception occurred while executing a Page,
       ensure that the Page is marked <code>&lt;%@ Page Async="true" %&gt;</code>.</p>
  </blockquote>
  
  <p>Now I dont have control over <code>CallSomeMethodWhichDoesAsyncOperations</code> and the method itself is not async but internally does some async fire and forget. What can I do to fix it? Have tried to change the controller to an <code>AsyncController</code> and/or making the method in the controller async.</p>
  
  <p>Edit:</p>
  
  <p>When I attempted to use an AsyncController I first tried, with the same result</p>
  
  <pre><code>public MyController : AsyncController
  {
      public ActionResult DoSomething()
      {
          CallSomeMethodWhichDoesAsyncOperations();
          return Json(new { success = successful }, JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>
  
  <p>And then </p>
  
  <pre><code>public MyController : AsyncController
  {
      public async Task&lt;ActionResult&gt; DoSomething()
      {
          CallSomeMethodWhichDoesAsyncOperations();
          return Json(new { success = successful }, JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>
  
  <p>Which did change the exception to the following "An asynchronous module or handler completed while an asynchronous operation was still pending."</p>