asp.net 获取系统的根目录
ASP.NET 根路径的获取
private string _ApplicationPath;
/// <summary>
/// 虚拟应用程序根路径
/// </summary>
public string ApplicationPath
{
get
{
_ApplicationPath = HttpContext.Current.Request.ApplicationPath;
if (_ApplicationPath.Length == 1)
{
_ApplicationPath = "";
}
return _ApplicationPath;
}
}
private string _CurrentPath;
/// <summary>
/// 当前的绝对路径
/// </summary>
public string CurrentPath
{
get
{
_CurrentPath = HttpContext.Current.Server.MapPath(".").ToLower();//当前的绝对路径(这里MapPath里的"."代表当前服务器)
if (_CurrentPath.Length == 1)
{
_CurrentPath = "";
}
return _CurrentPath;
}
}
private string _RootPath;
/// <summary>
/// 系统的根目录
/// </summary>
public string RootPath
{
get
{
_RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath).ToLower();//当前的绝对路径
if (_RootPath.Length == 1)
{
_RootPath = "";
}
return _RootPath;
}
}
/**//// <summary>
///
将Web站点下的绝对路径转换为相对于指定页面的虚拟路径
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="specifiedPath">绝对路径</param>
/// <returns>虚拟路径, 型如: http://www.cnblogs.com/</returns>
public static string ConvertSpecifiedPathToRelativePathForPage(Page page, string specifiedPath)
{
// 根目录虚拟路径
string virtualPath = page.Request.ApplicationPath;
// 根目录绝对路径
string pathRooted = HostingEnvironment.MapPath(virtualPath);
// 页面虚拟路径
string pageVirtualPath = page.Request.Path;
{
throw new Exception(string.Format("\"{0}\"是虚拟路径而不是绝对路径!", specifiedPath));
}
//(测试发现,pathRooted 在 VS2005 自带的服务器跟在IIS下根目录或者虚拟目录运行似乎不一样,
// 有此地方后面会加"\", 有些则不会, 为保险起见判断一下)
if (pathRooted.Substring(pathRooted.Length - 1, 1) == "\\")
{
specifiedPath = specifiedPath.Replace(pathRooted, "/");
}
else
{
specifiedPath = specifiedPath.Replace(pathRooted, "");
}
int pageNodesCount = pageNodes.Length - 2;
{
relativePath = "/.." relativePath;
}
{
// 如果存在 ".." , 则把最前面的 "/" 去掉
relativePath = relativePath.Substring(1, relativePath.Length - 1);
}
}
/**//// <summary>
/// 将Web站点下的绝对路径转换为虚拟路径
/// 注:非Web站点下的则不转换
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="specifiedPath">绝对路径</param>
/// <returns>虚拟路径, 型如: ~/</returns>
public static string ConvertSpecifiedPathToRelativePath(Page page, string specifiedPath)
{
string virtualPath = page.Request.ApplicationPath;
{
return specifiedPath;
}
{
specifiedPath = specifiedPath.Replace(pathRooted, "~/");
}
else
{
specifiedPath = specifiedPath.Replace(pathRooted, "~");
}
return relativePath;
}
asp.net 获取系统的根目录的更多相关文章
- File类_常见的方法(获取系统根目录与指定目录的容量)
获取系统根目录 import java.io.File; public class File_ListRoots { public static void main(String[] args) { ...
- ASP.NET路由系统实现原理:HttpHandler的动态映射
我们知道一个请求最终通过一个具体的HttpHandler进行处理,而我们熟悉的用于表示一个Web页面的Page对象就是一个HttpHandler,被用于处理基于某个.aspx文件的请求.我们可以通过H ...
- ASP.NET获取路径的方法
原文:[转载]ASP.NET获取路径的方法 HttpContext.Current.Request.PhysicalPath; // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\p ...
- 【转载】ASP.NET获取路径的方法
HttpContext.Current.Request.PhysicalPath; // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\project\website\Default ...
- ASP.NET获取客户端、服务器端的信息
ASP.NET获取客户端.服务器端基础信息 1. 在ASP.NET中专用属性: 获取服务器电脑名:Page.Server.ManchineName 获取用户信息:Page.User 获取客户端电脑名: ...
- ThinPHP命名空间,连接数据库是要修改的配置文件,Model数据模型层,跨控制器调用,如何获取系统常量信息,
一.命名空间(主要是为了实现自动加载类) *命名空间(相当于虚拟的目录),为了让类有一个统一的文件夹来管理(可以自动加载'类'),每个文件都要有命名空间*tp如何做命名空间:*TP框架下有一个初始命名 ...
- c# 如何获取项目的根目录
c# 如何获取项目的根目录 编写程序的时候,经常需要用的项目根目录.自己总结如下 1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设 ...
- 【转】cocos2d-x获取系统时间——2013-08-25 10
欢迎转载,本帖地址:http://blog.csdn.net/jinjian2009/article/details/9449585 之前使用过cocos2d-x获取系统时间,毫秒级的 long ge ...
- C# ,asp.net 获取当前,相对,绝对路径(转)
C# ,asp.net 获取当前,相对,绝对路径 一.C#获取当前路径的方法: . System.Diagnostics.Process.GetCurrentProcess().MainModule. ...
随机推荐
- C#学习(三)
通过类创建对象的过程称为类的实例化 匿名类型提供了一种方便的方法,可用来将一组只读属性封装到单个对象中,而无需首先显式定义一个类型. 要将匿名类型或包含匿名类型的集合作为参数传递给某一方法,可将参数作 ...
- EF中使用Contains方法
第一种情况 var db=new ECEntities(); var list=new []{"8","9"}; var result=from a in db ...
- 安装 SQL Server2008 安装程序规则支持提示“重新启动计算机”失败
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager 删除 PendingFileRenameOperations这个 ...
- 网页上facebook分享功能的具体实现
1,一个链接: 参数是要分享的页面的链接 代码如下: <a style="width:35px; height:40px; position:relative; top:10px; l ...
- 使用shiro标签遇到的部分问题的解决思路
最近几天,在shiro进行系统权限控制.在处理JSP页面的时候,遇到几个问题,纠结好几天,终于成功解决这些问题. 1.使用<shiro:principal>的时候,如何得到整个类的信息? ...
- IO流文件字符输入输出流,缓冲流
由于字节输入输出流在操纵Unicode字符时可能有乱码现象 于是就有了操作字符的输入输出流 Reader ,Writer和他们的子类FileReader,FileWrite(其实就是用来辅助构造的 W ...
- 【C#编程基础学习笔记】4---Convert类型转换
2013/7/24 技术qq交流群:JavaDream:251572072 教程下载,在线交流:创梦IT社区:www.credream.com [C#编程基础学习笔记]4---Convert类型转换 ...
- 多线程12-CyclicBarrier、CountDownLatch、Exchanger
1.CyclicBarrier 表示大家彼此等待,大家集合好后才开始出发,分散活动后又在指定地点集合碰面 package org.lkl.thead.foo; import java.util.con ...
- java中的hashcode方法作用以及内存泄漏问题
本文装载:http://hi.baidu.com/iduany/item/6d66dfc9d5f2da1650505870 hashCode()方法的作用&使用分析 一直以来都想写篇文章来说明 ...
- 配置mysql允许远程连接
开启MySQL数据库的远程连接权限: use mysql://进入数据库 grant all privileges on *.* to root@'%'identified by '123465789 ...