title: How to use MVC Action Results from regular web forms (faking ControllerContext)?
body: <p>We have a pluggable framework that returns <code>ActionResult</code> objects that render things to a browser.  One late breaking requirement is that our plugins should be callable from a regular ASP.NET Web Forms application.</p>
  
  <p>So far I have come up with this, which works for very basic ActionResults:</p>
  
  <pre><code>public class ActionResultTranslator {
  
      HttpContextBase _context;
  
      public ActionResultTranslator(HttpContextBase context ) {
  
          _context = context;
      }
  
      public void Execute(ActionResult actionResult) {
  
          ControllerContext fakeContext = new ControllerContext();
          fakeContext.HttpContext = _context;            
  
          actionResult.ExecuteResult(fakeContext);        
      }
  }
  </code></pre>
  
  <p>You would call the above from a web form with:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e) {
     HttpContextWrapper contextWrapper = new HttpContextWrapper(this.Context);
     var translator = new ActionResultTranslator(contextWrapper);
     translator.Execute(new RedirectResult("http://google.com"));     
  }
  </code></pre>
  
  <p>What else do I need to do to hook everything up?  For example, what if I wanted to return a ViewResult?</p>