对于这行代码;C#我想要的网址,而不是物理路径名称
string link = HttpContext.Current.Server.MapPath("/Contract/Details/" + this.ContractId.ToString());
我得到C盘上的物理路径名。
我想是的URL,即
http://localhost:1234/Contract/Details/1
如何获得呢?
对于这行代码;C#我想要的网址,而不是物理路径名称
string link = HttpContext.Current.Server.MapPath("/Contract/Details/" + this.ContractId.ToString());
我得到C盘上的物理路径名。
我想是的URL,即
http://localhost:1234/Contract/Details/1
如何获得呢?
// 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();
试试这个:
string url = HttpContext.Current.Request.Url.AbsoluteUri;
这将返回当前请求URL,也许这不是“/ Contract/Details/1” – 2010-08-18 10:31:34
这是不正确的。安东尼奥和蒂姆是对的。 – arame3333 2010-08-18 10:51:45
有.Net的路径,一个伟大的文章@http://west-wind.com/weblog/posts/132081.aspx
看看URL或PATHINFO财产。
Uri base = new Uri(“http://localhost:1234/”;); Uri file = new Uri(host,“/ Contract/Details /”+ this.ContractId.ToString());
string URL = file.AbsoluteUri;
蒂姆罗宾逊的答案是更好的因为他使用当前的请求主机 – 2010-08-18 10:30:17
这是正确的答案。 – arame3333 2010-08-18 10:48:28