title: How do access the HttpServerUtility in a WebAPI controller (MVC 4)
body: <p>I need to access the Server.MapPath(virtualPath) method in a controller in an MVC 4  ApiController.</p>
  
  <p>The answer is usually to access it from ControllerContext.HttpContext.Server.  However, unlike MvcControllers, the ControlerContext for an ApiController has no HttpContext.</p>
  
  <p>The WebApiAppication that is instantiated in Global.asax.cs has an HttpContext element (Context).  However, unlike MVC 3 and earlier, I can't find a way to access the WebApiApplication from a controller. (Earlier generations stored a reference to it in a static Instance variable. MVC 4 removes that.)</p>
  
  <p>Also, I'm trying to find something that will also work without a ton of extra scaffolding when I call the controller methods from a unit Test. I think I could access it, even in a WebApi Controller, using HttpContext.Current (at least it compiles), but I can't mock that for testing. (I'm talking unit testing here, where you call directly to the Controller methods.  I've seen some recent tutorials where you unit test with a thin HttpClient, and thus test the whole stack.  That seems more like low-level integration testing to me.)</p>
  
  <p>This doesn't seem like it should be that difficult, but I've spent several hours googling it and trying things, and my head's getting bloody from beating it against the wall.</p>