tags:

views:

59

answers:

4

For this line of code;

string link = HttpContext.Current.Server.MapPath("/Contract/Details/" + this.ContractId.ToString());

I get the physical pathname on C drive.

What I want is the url, ie

http://localhost:1234/Contract/Details/1

How do I get this?

+4  A: 

try this:

string url = HttpContext.Current.Request.Url.AbsoluteUri;
anishmarokey
this will return current request URL, maybe this is not a "/Contract/Details/1"
Antonio Bakula
This is not correct. Antonio and Tim are right on this.
arame3333
+3  A: 

There's a great article on .Net paths @ http://west-wind.com/weblog/posts/132081.aspx

Take a look at the Url or PathInfo property.

NinjaCat
+4  A: 
// Use the Uri constructor to form a URL relative to the current page
Uri linkUri = new Uri(HttpContext.Current.Request.Url, "/Contract/Details/" + this.ContractId.ToString());
string link = linkUri.ToString();
Tim Robinson
This is the correct answer.
arame3333
A: 

Uri base = new Uri("http://localhost:1234/";);

Uri file = new Uri(host, "/Contract/Details/" + this.ContractId.ToString());

string URL = file.AbsoluteUri;

Antonio Bakula
Tim Robinson answer is better becouse he is using current request host
Antonio Bakula