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 =3D HttpContext.Current;
string port =3D context.Request.ServerVariables["SERVER_PORT"];
if (port =3D=3D null || port =3D=3D "80" || port =3D=3D "443")
port =3D "";
else
port =3D ":" + port;
string protocol =3D =
context.Request.ServerVariables["SERVER_PORT_SECURE"];
if (protocol =3D=3D null || protocol =3D=3D "0")
protocol =3D "http://";
else
protocol =3D "https://";
string ret =3D string.Format("{0}{1}{2}{3}",
protocol,
context.Request.ServerVariables["SERVER_NAME"],
port,
context.Request.ApplicationPath);
if (!ret.EndsWith("/"))
ret =3D ret + "/";
return ret;
}
public static string GetUrl(string file)
{
if (file.StartsWith("~/"))
file =3D file.Substring(2);
else if (file.StartsWith("/"))
file =3D file.Substring(1);
=20
return HttpUtility.UrlPathEncode(GetRoot() + file);
}
}
[quoted text, click to view] "Riki" <riki@dontnagme.com> wrote in message =
news:uKud%23$VNGHA.3944@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?
>=20
> Page is a member of Context, and Page is derived from Control:
>=20
> Context.Page.ResolveUrl()
>=20
> --=20
>=20
> Riki=20
>=20