网上没有找到太合适的,自己写了一个,经过简单测试,满足各种情况
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#region 生成url应用程序绝对路径 (http://localhost:8080/website)
string absPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
absPath = absPath.Substring(System.Web.HttpContext.Current.Request.ApplicationPath.Length);
this._apppath = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.Replace(absPath, "");
this._apppath.TrimEnd('/');
#endregion
#region 生成应用程序硬盘物理路径(D:\wwwroot\website)
this._physicalpath = System.Web.HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString().TrimEnd('\\');
#endregion
#region 生成url应用程序皮肤绝对路径(http://localhost:8080/website/App_Themes/green)
System.Web.Configuration.PagesSection _ps = (System.Web.Configuration.PagesSection)System.Configuration.ConfigurationManager.GetSection("system.web/pages");
this._themename = _ps.Theme;
this._fullthemepath = string.Format("{0}/App_Themes/{1}", this._apppath, _ps.Theme).TrimEnd('/');
#endregion
string absPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
absPath = absPath.Substring(System.Web.HttpContext.Current.Request.ApplicationPath.Length);
this._apppath = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.Replace(absPath, "");
this._apppath.TrimEnd('/');
#endregion
#region 生成应用程序硬盘物理路径(D:\wwwroot\website)
this._physicalpath = System.Web.HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString().TrimEnd('\\');
#endregion
#region 生成url应用程序皮肤绝对路径(http://localhost:8080/website/App_Themes/green)
System.Web.Configuration.PagesSection _ps = (System.Web.Configuration.PagesSection)System.Configuration.ConfigurationManager.GetSection("system.web/pages");
this._themename = _ps.Theme;
this._fullthemepath = string.Format("{0}/App_Themes/{1}", this._apppath, _ps.Theme).TrimEnd('/');
#endregion