<%=System.Web.VirtualPathUtility.ToAbsolute("~")%>
This solves issues for getting paths for images if you use masterpages that can be consumed by pages in the web root and also from a subdirectory.
1 line of magic!
e.g. <a href='<%=System.Web.VirtualPathUtility.ToAbsolute("~")%>/somefile.aspx'>Link to file</a>
or <img src='<%=System.Web.VirtualPathUtility.ToAbsolute("~")%>/images/mylogo.jpg'/>