~ does not resolve to Request.ApplicationPath when website is hosted inside a sub directory
<p>I have an asp.net website which is inside a sub directory from root.</p>

<p>example : <code>http:localhost:6464/MyWebsite</code>  OR <code>http://www.myDomain.com/MySite</code></p>

<p>When i use a ASP.Net Image button and set its ImageUrl property as <code>"~/images/myimage.png"</code>, it does not resolve to <code>http:localhost:6464/MyWebsite/images/myimage.png</code> instead it resolves to  <code>http:localhost:6464/images/myimage.png</code> , and i get a error 200 (resource not found).</p>

<p>I read somewhere that for server controls i must use "~".</p>

<p>One solution i am currently using is , in webconfig i make an entry for BaseURL and set it as </p>

<pre><code>http:localhost:6464/MyWebsite/
</code></pre>

<p>and then use it as <code>&lt;asp:ImageButton ID="imgButton2" ImageURL="&lt;%=Context.Items["baseURL"]%&gt;images/myimage.png" runat="server"/&gt;</code>.</p>

<p>This works but i am checking if there is a more elegant way.</p>

<p><strong>UPDATED:</strong></p>

<p>So,  <strong>How to resolve to root of the application/virtual directory</strong>
Thanks.</p>
