Logo

【转载】ASP.NET获取路径的方法

photo

2022年05月17日

HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如

F:\XFU.NSQS\project\website\Default.aspx
HttpContext.Current.Request.PhysicalApplicationPath; // 获得当前程序运行的物理路径比

如F:\XFU.NSQS\project\website\
HttpContext.Current.Server.MapPath(@”\”); 这个就是在页面中的MapPath了.一样用法

HttpRuntime.AppDomainAppPath //这个是新发现的,很好用.

还有一个是用来处理在asp.net中调用dll文件,而DLL文件如果想知道当前的web站点的工作目录可

以用
System.AppDomain.CurrentDomain.BaseDirectory

网站在服务器磁盘上的物理路径: HttpRuntime.AppDomainAppPath
虚拟程序路径: HttpRuntime.AppDomainAppVirtualPath

HttpContext.Current.Request.ApplicationPath虚拟应用程序根路径
HttpContext.Current.Server.MapPath(“.”)当前的绝对路径
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)系统的

根目录

        sb.Append(string.Format(“当前请求的虚拟路径: {0}”,Server.HtmlEncode

(Request.CurrentExecutionFilePath)));
        sb.Append(string.Format(“获取当前应用程序的根目录路径: {0}”,

Server.HtmlEncode(Request.ApplicationPath)));
        sb.Append(string.Format(“当前请求的虚拟路径: {0}”,Server.HtmlEncode

(Request.FilePath)));
        sb.Append(string.Format(“当前请求的虚拟路径: {0}”,Server.HtmlEncode

(Request.Path)));
        sb.Append(string.Format(“获取当前正在执行的应用程序的根目录的物理文件系统路径:

{0}”, Server.HtmlEncode(Request.PhysicalApplicationPath)));
        sb.Append(string.Format(“获取与请求的 URL 相对应的物理文件系统路径: {0}”,

Server.HtmlEncode(Request.PhysicalApplicationPath)));

当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前应用程序的根目录路径: /aDirectory
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前正在执行的应用程序的根目录的物理文件系统路径: E:\Visual Studio 2005\
获取与请求的 URL 相对应的物理文件系统路径: E:\Visual Studio 2005\\aDirectory\

 

             sb.Append(string.Format(“获取项目完整的绝对路径: {0}”,

System.AppDomain.CurrentDomain.BaseDirectory.ToString()));
            //仅在尝试向此域中加载程序集之后,此属性才可用
            sb.Append(string.Format(“获取项目,它由程序集冲突解决程序用来探测动态创建的

程序集: {0}”, System.AppDomain.CurrentDomain.DynamicDirectory));
            sb.Append(string.Format(“获取磁盘上指向应用程序目录的物理路径。: {0}”,

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath));
            sb.Append(string.Format(“获取应用程序的虚拟根路径: {0}”,

System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath));
            sb.Append(string.Format(“获取站点的名称。: {0}”,

System.Web.Hosting.HostingEnvironment.SiteName));
            //sb.Append(string.Format(“获取此应用程序的虚拟路径提供程序。: {0}”,

System.Web.Hosting.HostingEnvironment.VirtualPathProvider));
            sb.Append(string.Format(“返回与 Web 服务器上的指定虚拟路径相对应的物理文件

路径。: {0}”, Server.MapPath(“sss.aspx”)));

 

转自:http://www.cnblogs.com/zhyt1985/archive/2009/10/29/1592245.html

 

所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

热门文章

修复群晖Synology Drive client右键菜单缺失问题 本教程主要解决windows10右键菜单中没有SynologyDrive菜单的问题,整体思路是找到...修复群晖SynologyDriveclient右键菜单缺失问题 作者:Pastore Antonio
1819 浏览量
docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 前言:有时候我们会在docker上下载一个镜像,或者是上传一个镜像到docker上,甚至有时候就是在...docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 作者:Pastore Antonio
1803 浏览量
configure: error: Package requirements (oniguruma) were not met configure:error:Packagerequirements(oniguruma)...configure:error:Packagerequirements(oniguruma)werenotmet 作者:Pastore Antonio
1533 浏览量
Adobe Acrobat Pro 激活 这里记录了一些AdobeAcrobat的激活教程和组件。浏览量:1,685 作者:Pastore Antonio
1531 浏览量
追寻日出,找回自己 为什么我要去追寻日出?其实我是一个很懒的人,每次都起不来,直到有一次我在租房中睡到了大天亮,阳光照...追寻日出,找回自己 作者:Pastore Antonio
1509 浏览量