代码之家  ›  专栏  ›  技术社区  ›  Gold

如何获取ASP.NET中的应用程序路径?

  •  31
  • Gold  · 技术社区  · 15 年前

    如何获取应用程序路径?仓路

    ASP.NET

    提前感谢

    7 回复  |  直到 7 年前
        1
  •  30
  •   hunter    15 年前

    获取服务器上ASP.NET应用程序的虚拟应用程序根路径。

    Request.ApplicationPath;
    

    http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx

    ResolveUrl("~/bin");
    
        2
  •  36
  •   Darin Dimitrov    15 年前
    Server.MapPath("~/bin")
    

    您也可以使用 HostingEnvironment.ApplicationPhysicalPath 财产。

        3
  •  14
  •   Raj Kumar - rajkrs    7 年前
    HttpContext.Current.Server.MapPath("~/bin") ;
    Application.StartupPath + "/bin";
    AppDomain.CurrentDomain.BaseDirectory + "/bin";
    
    //Note in Asp.net Core its little bit different
    public class ValuesController : ControllerBase
    {
            IHostingEnvironment _hostingEnvironment;
            public ValuesController(IHostingEnvironment hostingEnvironment)
            {
                _hostingEnvironment = hostingEnvironment;
                string applicationPath = _hostingEnvironment.ContentRootPath;
                string wwwrootPath = _hostingEnvironment.WebRootPath;
            }
    }
    

    还有很多在 blog

        4
  •  13
  •   Carsten    13 年前

    使用以下代码段:

    string strPath = HttpContext.Current.Server.MapPath("~/bin");
    
        5
  •  12
  •   jenson-button-event    11 年前

    我需要这个在 app_start 如果还没有 HttpContext 因此 Request Server 不是选项。

    这就成功了:

    System.Web.HttpRuntime.BinDirectory
    
        6
  •  3
  •   Vishal Gavle    13 年前
    Server.MapPath("~/bin")
    

    您也可以使用 Request.PhysicalApplicationPath

        7
  •  0
  •   Amin Golmahalleh    7 年前

    HostingEnvironment.MapPath() VS Server.MapPath() server.mappath用于为ASP.NET映射Web服务器上的物理位置。 String path = HttpContext.Current.Server.MapPath("~/myFolder/myFile.txt"); server.map path指定要映射到物理目录的相对路径或虚拟路径。

    样品:

     string path=System.Web.Hosting.HostingEnvironment.MapPath(@"~/Files/ExamResult.rdlc");
    

    有关详细信息,请访问此 Link

    推荐文章