Url.Content in asp.net web-forms

白昼怎懂夜的黑 提交于 2020-01-10 17:28:53

问题


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 ?


回答1:


Try adding runat="server" to your tag.




回答2:


As rapadai mentioned above, the equivalent of

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

in webforms is

Page.ResolveUrl("~/path/to/file.ext") // Webforms



回答3:


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:


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




回答5:


<%= Page.ResolveUrl("~/Path/To/Page") %>


来源:https://stackoverflow.com/questions/6331023/url-content-in-asp-net-web-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!