System.Web.HttpContext.Server.MapPath()

总注:Server.MapPath获得的路径都是服务器上的物理路径,也就是常说的绝对路径
1、Server.MapPath("/")
注:获得应用程序根目录所在的位置,如 C:\Inetpub\wwwroot\。
2、Server.MapPath("./")
注:获得所在页面的当前目录,等价于Server.MapPath("")。
3、Server.MapPath("../")
注:获得所在页面的上级目录。
4、Server.MapPath("~/")
注:获得当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置,如C:\Inetpub\wwwroot\Example\。

时间: 2024-07-29 14:18:41

System.Web.HttpContext.Server.MapPath()的相关文章

慎用System.Web.HttpContext.Current

每当控制流离开页面派生的Web表单上的代码的时候,HttpContext类的静态属性Current可能是有用的. 使用这个属性,我们可以获取当前请求(Request),响应(Response),会话(Session,)和应用程序对象(Application objects)以及请求更多服务. 以下面的代码为例. private void Page_Load(object sender, System.EventArgs e) { MyClass myClass = new MyClass();

System.Web.HttpContext.Current.Session为NULL值的问题?

自定义 HTTP 处理程序,从IHttpHandler继承,在写System.Web.HttpContext.Current.Session["Value"]的时 候,没有问题,但想将这个Session写到某个变量时或判断是否为空时 如:HttpContext.Current.Session["Value"]==null,发现Session的值为NULL,后来查MSDN,看到 “在自定义 HTTP 处理程序中实现 IRequiresSessionState 接口,以

asp.net后台导出excel的方法:使用System.Web.HttpContext.Current.Response导出excel

程序如下: 程序描述:该程序能够实现有大型的标题,以及表头等功能 调用方法:ToExcel(newDt, FileName); protected void ToExcel(DataTable dt, string FileName) { StringBuilder sb = new StringBuilder(); sb.Append("<style type=\"text/css\">"); sb.Append("<!--"

System.Web.HttpContext.Current.Session获取值出错

在自定义类库CS文件里使用System.Web.HttpContext.Current.Session获取Session时提示错误:未将对象引用设置到对象的实例. 一般情况下通过这种方式获取Session值不会有问题,不过应特别注意要使用session必须要page_load方法执行以建立了page对象以后才有session的使用目标,此时先检测Session是否为Null再调用值是不会提示错误的. 如果直接在Page页面中定义一个全局变量取Session的值就会提示未设置实例的错误!使用App

System.Web.HttpContext.Current 跟踪分析

public static HttpContext Current { get { return ContextBase.Current as HttpContext; } set { ContextBase.Current = (object) value; } }   internal class ContextBase { internal static object Current { get { return CallContext.HostContext; } [SecurityPe

HttpContext.Current.Server.MapPath(&quot;/&quot;) 未将对象设置到对象的实例异常。

多线程中的System.Web.HttpContext.Current.Server.MapPath("/") 多线程中Server.MapPath会失效... 网上找到几种解决方法,现在整理如下: 第一种: System.Web.HttpContext.Current.Server.MapPath("/")  这个常用来表示网站的根目录,但是在多线程中,会发生未将对象引用设置到对象的实例. 所以不要分布在不同的类中,尽量在一个全局位置,然后其它类共用这个,毕竟网站

Server.MapPath查询路径那几件事

主要总结Server.MapPath 这个方法的使用以及使用的场景,不是什么时候都适合使用: 1.实现功能: Server.MapPath能够获取指定URL相对服务器的物理路径,在IIS服务端,能够根据文件名来获取该文件的物理路径: 2.存在命令空间: System.Web.HttpContext.Current.Server.MapPath 以及System.web.MVC.Control.Server.Mapth; 3.使用情况: 既然是System.Web.HttpContent 也及时表

转:Server.MapPath相关

如果你从Page类继承的类中执行这条语句,才可以简单地使用 DataBase = Server.MapPath("data.mdb");否则写全命名空间:System.Web.HttpContext.Current.Server.MapPath(); 总注:Server.MapPath获得的路径都是服务器上的物理路径,也就是常说的绝对路径1.Server.MapPath("/")注:获得应用程序根目录所在的位置,如 C:\Inetpub\wwwroot\.2.Ser

asp.net .ashx,cs文件使用server.mappath解决方法

asp.net .ashx文件使用server.mappath解决方法: System.Web.HttpContext.Current.Server.MapPath 在类文件中使用: System.Web.HttpServerUtility server = System.Web.HttpContext.Current.Server;server.MapPath(...)