title: Get base URL of ServiceStack instance
body: <p>What's the best way to determine the base URL path at which a ServiceStack instance is running? For example, if I configure ServiceStack to run at the "/api" base URL in web.config, how do I get the string "/api"? I would like to get this value in order to construct URLs of arbitrary request DTOs, as HATEOAS style documentation.</p>
  
  <p>For example, if I have a request DTO <code>SomeRequest</code> with a <code>[Route("/someRequest")]</code> attribute, the full URL of this request would be "/api/someRequest". The <code>ToUrl</code> extension method returns just part of the path below the base URL:</p>
  
  <pre><code>new SomeRequest().ToUrl() // returns "/someRequest"
  </code></pre>
  
  <p>I haven't found any easy way to do this. It seems that there are no config properties exposed by ServiceStack that return the "/api" base path value. <a href="https://stackoverflow.com/questions/3651800/how-to-read-system-webserver-configuration-section">Inspecting web.config</a> to get the ServiceStack handler path might be possible with ServiceStack 4 but I'm having trouble figuring out how to do it with our current SS 3 configuration.</p>
  
  <p>The <code>Request.GetAbsolutePath()</code> method will produce the full path of the current request, e.g. "/api/someRequest", and then I could maybe do some string comparison between this and the <code>ToUrl()</code> extension method to determine the base path, but that also seems like a pretty fragile solution.</p>
  
  <p>Is there any better way to get this base URL?</p>