zoukankan      html  css  js  c++  java
  • asp.net 获取网站根目录

    获取网站根目录的方法有几种如:

    Server.MapPath(Request.ServerVariables["PATH_INFO"])
    Server.MapPath("/")
    Server.MapPath("")
    Server.MapPath(".")
    Server.MapPath("../")
    Server.MapPath("..")
    Page.Request.ApplicationPath
    运行结果:
    C:\Inetpub\wwwroot\EnglishClub\manage\WebForm1.aspx
    C:\Inetpub\wwwroot\
    C:\Inetpub\wwwroot\EnglishClub\manage
    C:\Inetpub\wwwroot\EnglishClub\manage
    C:\Inetpub\wwwroot\EnglishClub\
    C:\Inetpub\wwwroot\EnglishClub

    以上的方法可以在.aspx中访问,但是如果你在。cs文件就不能用。

     

    HttpContext.Current.Server.MapPath();
    System.Web.HttpContext.Current.Request.PhysicalApplicationPath   

    在.cs文件中可以用。

    但是HttpContext.Current.Server.MapPath();这个获取的是文件的路径而不是根目录。

    只有System.Web.HttpContext.Current.Request.PhysicalApplicationPath    这个才是获取的根目录,在写获取数据库路径是应该用这个,其他的都有问题。

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    netty中Pipeline的ChannelHandler执行顺序案例详解
    Pi-设置无线
    Pi1-Centos
    gitlab升级
    ansible
    我也玩Jenkins
  • 原文地址:https://www.cnblogs.com/weiling/p/1689124.html
Copyright © 2011-2022 走看看