ASP.Net C# ResolveClientUrl inside Class

Marco picture Marco · Feb 10, 2010 · Viewed 18.1k times · Source

I have the following code:

public class NavigationPath
{
    private string menuItems = "<li>" +
                                    "<a href=\"#\">home</a>" +
                               "</li>";

But I would like to have:

public class NavigationPath
{
    private string menuItems = "<li>" +
                                    "<a href=\"" + ResolveClientUrl("~/home.aspx") + "\">re</a>" +
                               "</li>";

However, I am not able to use ResolveClientUrl inside a Class. Any ideas?

Answer

Paulus E Kurniawan picture Paulus E Kurniawan · Feb 10, 2010

Instead of calling ResolveClientUrl on the Page object (or any controls), you can also use VirtualPathUtility.ToAbsolute("~/home.aspx"); which will give you the same result as calling ResolveUrl("~/home.aspx");