Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of tilde (~) in asp.net path

Tags:

c#

asp.net

i'm working on an asp.net app, the following link works in IE but not in FF.

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

Isn't the tilde something that can only be used in asp.net server controls. Where it will be replaced by an actual path?

Is it possible to use the tilde in an 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! 

The link generated by ASP.NET is:

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

Is this by design?

like image 763
Michel Avatar asked Jun 19 '10 22:06

Michel


People also ask

What does tilde mean in path?

The tilde (~) is a Linux "shortcut" to denote a user's home directory. Thus tilde slash (~/) is the beginning of a path to a file or directory below the user's home directory. For example, for user01, file /home/user01/test. file can also be denoted by ~/test.

What is mean in asp net?

It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name stands for Active Server Pages Network Enabled Technologies. ASP.NET (software) Developer(s)


1 Answers

You are correct, it only works in server controls. You've got these basic options:

Change to HyperLink to run as a Web Control:

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

Or, run the anchor on the server side as an HTML Control:

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

Or, use Page.ResolveUrl:

<a href="<%= Page.ResolveUrl("~/BusinessOrderInfo/page.aspx") %>">...</a> 
like image 164
Dean Harding Avatar answered Oct 03 '22 16:10

Dean Harding