对于这行代码;
string link = HttpContext.Current.Server.MapPath("/Contract/Details/" + this.ContractId.ToString());
我在C盘上获得了物理路径名。
我想要的是网址,即
http://localhost:1234/Contract/Details/1
我如何得到这个?
答案 0 :(得分:4)
试试这个:
string url = HttpContext.Current.Request.Url.AbsoluteUri;
答案 1 :(得分:4)
// 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();
答案 2 :(得分:3)
关于.Net路径@ http://west-wind.com/weblog/posts/132081.aspx
的文章很棒查看Url或PathInfo属性。
答案 3 :(得分:0)
Uri base = new Uri(“http://localhost:1234/”;);
Uri file = new Uri(host,“/ Contract / Details /”+ this.ContractId.ToString());
string URL = file.AbsoluteUri;