I’m trying to do this:
<a href="~/Cases/SupRequestSearch.aspx" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">Search request</a>
so I need the ~ to be rendered as http://myserver/app/...
in mvc I would do
<a href="<%=Url.Content(" rel="nofollow noreferrer noopener"~/Cases/SupRequestSearch.aspx")%>>Search request</a>
is there something similar in asp.net web forms ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
As rapadai mentioned above, the equivalent of
Url.Content("~/path/to/file.ext") // MVC
in webforms is
Page.ResolveUrl("~/path/to/file.ext") // Webforms
Method 2
Try adding runat="server" to your tag.
Method 3
Try this:
<asp:hyperlink id="Search" NavigateUrl="~/Cases/SupRequestSearch.aspx" runat="server" />
or just
<a href="~/Cases/SupRequestSearch.aspx" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" id="Search" runat="server">Search request</a>
Method 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
Method 5
<%= Page.ResolveUrl("~/Path/To/Page") %>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0