Url.Content in asp.net web-forms

2019-02-07 21:35发布

I'm trying to do this:

<a href="~/Cases/SupRequestSearch.aspx">Search request</a>

so I need the ~ to be rendered as http://myserver/app/...

in mvc I would do

<a href="<%=Url.Content("~/Cases/SupRequestSearch.aspx")%>>Search request</a>

is there something similar in asp.net web forms ?

5条回答
Root(大扎)
2楼-- · 2019-02-07 21:42

If you don't have either Url or Page you can still use

VirtualPathUtility.ToAppRelative(string) or VirtualPathUtility.ToAbsolute(string)

You still need to be within a web context of course - or this doesn't make sense.

See also : ResolveUrl without an ASP.NET Page

查看更多
叼着烟拽天下
3楼-- · 2019-02-07 21:44

Try this:

<asp:hyperlink  id="Search" NavigateUrl="~/Cases/SupRequestSearch.aspx" runat="server" />

or just

<a href="~/Cases/SupRequestSearch.aspx" id="Search" runat="server">Search request</a>
查看更多
家丑人穷心不美
4楼-- · 2019-02-07 21:48
<%= Page.ResolveUrl("~/Path/To/Page") %>
查看更多
戒情不戒烟
5楼-- · 2019-02-07 21:52

As rapadai mentioned above, the equivalent of

Url.Content("~/path/to/file.ext") // MVC

in webforms is

Page.ResolveUrl("~/path/to/file.ext") // Webforms
查看更多
趁早两清
6楼-- · 2019-02-07 21:55

Try adding runat="server" to your tag.

查看更多
登录 后发表回答