在做.NET编程时,因为目录结构问题往往很难使用相对路径,而用应用程序的URL绝对路径来代替。但这样会涉及到应用程序名称,端口问题,我大概写了一个获取URL路径的方法

 

 URL绝对路径

            #region 生成url应用程序绝对路径
            
string absPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
            absPath = absPath.Substring(System.Web.HttpContext.Current.Request.ApplicationPath.Length);
            
string asbUrl = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
            
this._apppath = asbUrl.Substring(0, asbUrl.IndexOf(absPath));
            
this._apppath.TrimEnd('/');
            
#endregion


硬盘物理路径和皮肤路径

            #region 生成应用程序硬盘物理路径
            
this._physicalpath = System.Web.HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString().TrimEnd('\\');
            
#endregion

            
#region 生成url应用程序皮肤绝对路径
            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


 

相关文章:

  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2021-12-29
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2021-11-10
  • 2021-08-15
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案