title: ASP.NET: How to get the virtual path of a file from a generic handler?
body: <p>How can i resolve a virtual path to a file into a path, suitable for the browser, from within a generic .ashx handler?</p>
  
  <p>e.g. i want to convert:</p>
  
  <pre><code>~/asp/ClockState.aspx
  </code></pre>
  
  <p>into</p>
  
  <pre><code>/NextAllowed/asp/ClockState.aspx
  </code></pre>
  
  <hr>
  
  <p>If i were a WebForm <code>Page</code>, i could call <code>ResolveUrl</code>:</p>
  
  <pre><code>Page.ResolveUrl("~/asp/ClockState.aspx")
  </code></pre>
  
  <p>which resolves to:</p>
  
  <pre><code>/NextAllowed/asp/ClockState.aspx
  </code></pre>
  
  <hr>
  
  <p>But i'm not a WebForm Page, i'm a generic handler. You know, that <code>IHttpHandler</code> object with all kinds of things injected:</p>
  
  <pre><code>public class ResetClock : IHttpHandler 
  {
      public void ProcessRequest (HttpContext context) 
      {
          //[process stuff]
  
          //Redirect client
          context.Response.Redirect("~/asp/ClockState.aspx", true);
      }
  
      public bool IsReusable { get { return false; } }
  }
  </code></pre>