【发布时间】:2010-08-18 10:14:55
【问题描述】:
对于这行代码;
string link = HttpContext.Current.Server.MapPath("/Contract/Details/" + this.ContractId.ToString());
我得到了 C 盘上的物理路径名。
我要的是url,即
http://localhost:1234/Contract/Details/1
我如何得到这个?
【问题讨论】:
对于这行代码;
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;
【讨论】:
.Net 路径上有一篇很棒的文章@http://west-wind.com/weblog/posts/132081.aspx
查看 Url 或 PathInfo 属性。
【讨论】:
Uri base = new Uri("http://localhost:1234/";);
Uri 文件 = new Uri(host, "/Contract/Details/" + this.ContractId.ToString());
字符串 URL = file.AbsoluteUri;
【讨论】: