【发布时间】:2013-11-13 10:00:27
【问题描述】:
我想得到除了当前页面之外的所有URL路径,例如:我的URL是http://www.MyIpAddress.com/red/green/default.aspx 我只想得到“http://www.MyIpAddress.com/red/green/”。我怎么能得到。我正在做的像
string sPath = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).OriginalString; System.Web.HttpContext.Current.Request.Url.AbsolutePath;
sPath = sPath.Replace("http://", "");
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
Response.Write(sPath.Replace(sRet, ""));
它在新 System.IO.FileInfo(sPath) 上显示异常,因为 sPath 包含“localhost/red/green/default.aspx”,表示“不支持给定路径的格式。”
【问题讨论】: