Reputation: 10193
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?
Upvotes: 1
Views: 199
Reputation: 20693
Uri base = new Uri("http://localhost:1234/";);
Uri file = new Uri(host, "/Contract/Details/" + this.ContractId.ToString());
string URL = file.AbsoluteUri;
Upvotes: 0
Reputation: 54734
// 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();
Upvotes: 4
Reputation: 10194
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.
Upvotes: 3
Reputation: 11397
try this:
string url = HttpContext.Current.Request.Url.AbsoluteUri;
Upvotes: 4