Using tildes (~) in asp.net path

I am working on an asp.net application, the following link works in IE, but not in FF.

<a href="~/BusinessOrderInfo/page.aspx" > 

This is not a tilde that can only be used with asp.net server controls. Where will it be replaced in the actual way?

Can tilde be used in anchor tag? If so, what does it mean?

When I'm at the root, the link works

 www.myserver.com/default.aspx, click the link, ok! www.myserver.com/otherpart/default.aspx, click the link, not ok! 

Link generated by ASP.NET:

 www.myserver.com/otherpart/~BusinessOrderInfo/page.aspx 

Is it for design?

+62
Jun 19 2018-10-19T00:
source share
5 answers

You are right, it works only in server management tools. You have the following main options:

Change to HyperLink to start Web Control :

 <asp:HyperLink NavigateUrl="~/BusinessOrderInfo/page.aspx" Text="Whatever" runat="server" /> 

Or launch the server side anchor as HTML control :

 <a href="~/BusinessOrderInfo/page.aspx" runat="server" > 

Or use Page.ResolveUrl :

 <a href="<%= Page.ResolveUrl("~/BusinessOrderInfo/page.aspx") %>">...</a> 
+87
Jun 19 '10 at 23:03
source share

HTML controls can be turned into server controls by adding the runat = "server" attribute.

 <a href="~/BusinessOrderInfo/page.aspx" runat="server"> 
+19
Jun 19 '10 at 23:12
source share

Tilda refers to the root directory of the application and will be correctly translated into management properties such as NavigateUrl.

I understand that if you use it in tags with an open HTML tag, it will not be broadcast by ASP.Net.

+8
Jun 19 '10 at 23:06
source share

If you delete the tilde and use only the slash, you get the same result, that is, pointing to the root folder in the current domain:

 <a href="/BusinessOrderInfo/page.aspx" > 
0
Feb 16 '17 at 15:32
source share

This function can also be used to resolve paths for non-server items.

 VirtualPathUtility.ToAbsolute($"~/App_Themes/Default/Icons/myimage.gif") 
-one
Nov 09 '17 at 14:52
source share



All Articles