public class foo : System.Web.UI.Control
{
public foo()
{
var a = new HyperLink(){ Text="Test", NavigateUrl="~/abc.aspx"};
this.Controls.Add(a);
}
}
The above code works properly, and when added to a page will successfully identify the tilde / ~ symbol and convert the url into a relative url.
However, when I change the derivation of the class to System.Web.UI.WebControl
it does absolutely nothing, and leaves the tilde / ~ intact.
I had a look at System.Web.UI.Control
which implements the IUrlResolutionService
interface, but still can't see开发者_开发知识库m to get System.Web.UI.WebControl
to resolve urls.
You can try the System.Web.VirtualPathUtility class:
public foo()
{
var a = new HyperLink()
{
Text="Test",
NavigateUrl=VirtualPathUtility.ToAbsolute("~/abc.aspx")
};
this.Controls.Add(a);
}
I usually do this to get root and them map my path:
HostingEnvironment.ApplicationVirtualPath() + "/mypath/mypage.aspx"
精彩评论