Server.MapPath相关
来源:互联网 发布:程序员喜欢的女生类型 编辑:程序博客网 时间:2024/05/17 08:31
如果你从Page类继承的类中执行这条语句,才可以简单地使用
DataBase = Server.MapPath("data.mdb");
否则写全命名空间:System.Web.HttpContext.Current.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\。
在多线程里面使用HttpContext.Current,HttpContext.Current是得到null的.
所以在线程调用方法,方法中类里面的System.Web.HttpContext.Current.Server.MapPath() 获取不到对象。
应该这样用:
public static string MapPath(string strPath)
{
if (HttpContext.Current != null)
{
return HttpContext.Current.Server.MapPath(strPath);
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\"))
{
//strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
strPath = strPath.TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
- Server.MapPath相关
- Server.MapPath()相关
- Server.MapPath()相关
- 几个和server.mappath相关的符号
- Server.MapPath()
- Server.MapPath
- Server.MapPath
- Server.MapPath()
- Server.MapPath()
- Server.MapPath
- Server.MapPath(".") Server.MapPath("./") Server.MapPath("/") Server.MapPath用法详解
- server .mappath
- SERVER.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- struts2+spring3+hibernate3+ireport+防止重复登录
- 一位硕士毕业生三个月求职经历与经验的结晶
- JAVA相关基础知识1
- jetty学习2-WebAppContext
- 最近抽空在学习VIM,找到了一个介绍快捷方式的,留下做个备注
- Server.MapPath相关
- 使用SVN+CruiseControl+ANT实现持续集成之三----构建操作及监视
- 移动开发中的通信架构(三)
- Oracle 学习笔记
- .net中上传视频并将各种视频文件转换成.flv格式
- redhat 系统信息查看命令大全
- 收藏一款好用的基于.NET的配置文件设计工具
- oracle中如何移动控制文件,数据文件,日志文件
- android屏幕截图