<p>What is the best way to use ResolveUrl() in a Shared/static function in Asp.Net? My current solution for VB.Net is:</p>

<pre><code>Dim x As New System.Web.UI.Control
x.ResolveUrl("~/someUrl")
</code></pre>

<p>Or C#:</p>

<pre><code>System.Web.UI.Control x = new System.Web.UI.Control();
x.ResolveUrl("~/someUrl");
</code></pre>

<p>But I realize that isn't the best way of calling it.</p>

[{'answer_id': 26807, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 7, 'selected': True, 'text': '<p>I use <a href="http://msdn.microsoft.com/en-us/library/system.web.virtualpathutility.aspx" rel="noreferrer">System.Web.VirtualPathUtility.ToAbsolute</a>.</p>\n'}, {'answer_id': 26812, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 2, 'selected': False, 'text': '<p>I tend to use HttpContext.Current to get the page, then run any page/web control methods off that.</p>\n'}, {'answer_id': 528198, 'author': 'jdw', 'author_id': 64181, 'author_profile': 'https://Stackoverflow.com/users/64181', 'pm_score': 5, 'selected': False, 'text': '<p>It\'s worth noting that although System.Web.VirtualPathUtility.ToAbsolute is very useful here, it is <strong>not</strong> a perfect replacement for Control.ResolveUrl.</p>\n\n<p>There is at least one significant difference: Control.ResolveUrl handles Query Strings very nicely, but they cause VirtualPathUtility to throw an HttpException. This can be absolutely mystifying the first time it happens, especially if you\'re used to the way that Control.ResolveUrl works.</p>\n\n<p>If you know the exact structure of the Query String you want to use, this is easy enough to work around, viz:</p>\n\n<pre><code>public static string GetUrl(int id)\n{\n    string path = VirtualPathUtility.ToAbsolute("~/SomePage.aspx");\n    return string.Format("{0}?id={1}", path, id);\n}\n</code></pre>\n\n<p>...but if the Query String is getting passed in from an unknown source then you\'re going to need to parse it out somehow. (Before you get too deep into that, note that System.Uri  might be able to do it for you).</p>\n'}]
['https://Stackoverflow.com/questions/26796', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1414/']