/// <summary>
/// 获取网站根目录Url
/// </summary>
public static string Root
{
get
{
if (System.Web.HttpContext.Current.Cache["WebAppRoot"] == null)
{
string AppPath = string.Empty;
HttpContext httpCurrent = HttpContext.Current;
HttpRequest request;
request = httpCurrent.Request;
string UrlAuthority = request.Url.GetLeftPart(UriPartial.Authority);
if (request.ApplicationPath == null || request.ApplicationPath == "/")//直接安装在Web站点
{
AppPath = UrlAuthority;
}
else //安装在虚拟子目录下
{
AppPath = UrlAuthority + request.ApplicationPath;
}
//return AppPath;
System.Web.HttpContext.Current.Cache.Insert("WebAppRoot", AppPath, null, DateTime.Now.AddHours(1), TimeSpan.Zero);
}
return (string)System.Web.HttpContext.Current.Cache["WebAppRoot"];
}
}