相对 URL 在 System.Web.UI.UserControl 中不起作用
public class foo : System.Web.UI.Control
{
public foo()
{
var a = new HyperLink(){ Text="Test", NavigateUrl="~/abc.aspx"};
this.Controls.Add(a);
}
}
上面的代码工作正常,当添加到页面时将成功识别波浪号/~符号并将url转换为相对url。
但是,当我将类的派生更改为 System.Web.UI.WebControl 时,它绝对不执行任何操作,并且保持波浪号 / ~ 不变。
我查看了实现了 IUrlResolutionService 接口的 System.Web.UI.Control ,但似乎仍然无法获取 System.Web.UI.WebControl 来解析 url。
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 seem to get System.Web.UI.WebControl
to resolve urls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试 System.Web.VirtualPathUtility 类:
You can try the System.Web.VirtualPathUtility class:
我通常这样做是为了获得 root 权限,然后它们映射我的路径:
HostingEnvironment.ApplicationVirtualPath() + "/mypath/mypage.aspx"
I usually do this to get root and them map my path:
HostingEnvironment.ApplicationVirtualPath() + "/mypath/mypage.aspx"