Link url problem asp.net

Posted by Nerdanalysis under IIS on 3/25/2012 | Points: 10 | Views : 2199 | Status : [Member] | Replies : 4
Hi all,

i am facing problems in url. Some time it picks up . ./nerd/default.aspx sometimes doent.

So what is difference in

../blah/default.aspx
blah/default.aspx
~/blah/default.aspx




Responses

Posted by: Jmckamal on: 3/27/2012 [Member] Starter | Points: 25

Up
0
Down

There are four types of paths available in asp.net:

1. Absolute paths
2. Relative Path
3. Root Relative Path / Absolute virtual path(another name).
4. Application Relative Path / Domain relative path(another name).

1. Absolute Path: (We usually use this to refer external websites).

Ex: http://test/test1/test2.jpg


2. Relative Path:

There are two types of Relative Paths.

1. client side

2. Server side

Ex: ../test1/test2.jpg


3. Root Relative Path / Absolute virtual path: (normally used to hard code the path, not recommanded one)

Ex: /test1/test2/test3.jpg


4. Application Relative Path / Domain relative path :

- comes with ~ symbol
- Normally ~ means - users home directory.


Now we will come to your problem solution. Normally if you face any problem with ~ , you can also use like this:

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "directoryname/filename.extn")


I will tell you one more interesting thing here - this ~ will work only with server side. but when you come to client side this will work with IE not with firefox.

During that time we have two kind of options (Navigateurl/Page.ResolveUrl) to use ~.

<asp:HyperLink NavigateUrl="~/yourdirectoryname/page.aspx" Text="Whatever" />
Or, use Page.ResolveUrl:

<a href="<%= Page.ResolveUrl("~/yourdirectoryname/page.aspx") %>">...</a>

HOpe this helps you.

Thanks,
Kamal

Nerdanalysis, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 3/28/2012 [Member] Bronze | Points: 25

Up
0
Down
Jmckamal

Good Explanation..

Super

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Nerdanalysis, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 3/28/2012 [Member] Bronze | Points: 25

Up
0
Down
Nerdanalysis

This is Very Good Explanation

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Nerdanalysis, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: dhirenkaunar-15094 on: 6/9/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for nice explanation : Jmckamal

Thanks & Rgards,
Dhiren Kumar Kaunar

Nerdanalysis, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response