title: ASP.NET MVC3 Root-relative path to virtual path in Controller or Model
body: <p>This sounds like a simple enough question, but can't find the answer for the life of me. How does one convert a root-relative url (<code>~/my/path</code>) to a virtual path (<code>/mywebsite/my/path</code>) in the Controller and/or Model?</p>
  
  <p>On a view it's easy enough to do, just call <code>@Url.Content("~/my/path/")</code>. And getting the physical path in the controller is just as easy using <code>Server.MapPath("~/my/path")</code>. But I can't figure out how to get the virtual path in the controller.</p>
  
  <p>My main issue is that I have a root-relative path of an image that I will be passing to a JSON object that will be returned. In most cases this will be read by javascript and put on the page somewhere, and I can't use <code>@Url.Content</code> in my javascript code. Also, in some instances this JSON object will be used by an external application that won't understand what the <code>~</code> means.</p>