zoukankan      html  css  js  c++  java
  • ASP.NET中常用的两个路径

    在做.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


  • 相关阅读:
    十五分钟建立精美网站
    WebMatrix教程(一) (关注Microsoft 的最新武器:建立你的第一个WebMatrix网站)
    数据同步框架MS Sync Framework IDE快速开发支持Local Database Cache
    Interview SeniorSoftwareEngineers
    学JQuery最新免费教程[转]
    Visual Studio 2010 支持HTML5 和 CSS3
    Orchard:打包和共享模块
    CSLA.NET 框架开发实战
    如何真正提高ASP.NET网站的性能
    敏捷英语
  • 原文地址:https://www.cnblogs.com/freeton/p/1693930.html
Copyright © 2011-2022 走看看