Well I look in the documentation and HttpContext don't seem to have a Page member, so..
We'll I have to see if it compiles.
True to tell there is a CurrentHandler property though, which I could cast to a page.
But... although it's likely there would be a current page, it's not alway true.
Anyway I end up doing some code like that:
public class WebUrl
{
public static string GetRoot()
{
HttpContext context = HttpContext.Current;
string port = context.Request.ServerVariables["SERVER_PORT"];
if (port == null || port == "80" || port == "443")
port = "";
else
port = ":" + port;
string protocol = context.Request.ServerVariables["SERVER_PORT_SECURE"];
if (protocol == null || protocol == "0")
protocol = "http://";
else
protocol = "https://";
string ret = string.Format("{0}{1}{2}{3}",
protocol,
context.Request.ServerVariables["SERVER_NAME"],
port,
context.Request.ApplicationPath);
if (!ret.EndsWith("/"))
ret = ret + "/";
return ret;
}
public static string GetUrl(string file)
{
if (file.StartsWith("~/"))
file = file.Substring(2);
else if (file.StartsWith("/"))
file = file.Substring(1);
return HttpUtility.UrlPathEncode(GetRoot() + file);
}
}
"Riki" <ri**@dontnagme.com> wrote in message news:uK****************@tk2msftngp13.phx.gbl...
Lloyd Dupont wrote: I can't use Control.ResolveUrl because I need to write the conversion
in a utility class.
However I know the current context.
How could I convert the URL to one usable by the user?
Page is a member of Context, and Page is derived from Control:
Context.Page.ResolveUrl()
--
Riki