最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 获取url路径方法
时间:2011-01-02 编辑:简简单单 来源:一聚教程网
解决的方法主要是依靠 httpcontext 对象,比如
httpcontext.current.request.physicalpath; // 获得当前页面的完整物理路径.比如 f:xfu.nsqsprojectwebsitedefault.asp教程x
httpcontext.current.request.physicalapplicationpath; // 获得当前程序运行的物理路径比如f:xfu.nsqsprojectwebsite
httpcontext.current.server.mappath(@""); 这个就是在页面中的mappath了.一样用法
httpruntime.appdomainapppath //这个是新发现的,很好用.
还有一个是用来处理在asp.net教程中调用dll文件,而dll文件如果想知道当前的web站点的工作目录可以用
system.appdomain.currentdomain.basedirectory
简单三种方法
习asp.net上传文件时,发现有三种方法可以获取当前web程序目录物理路径:
方法一:
string spath = system.io.path.getdirectoryname(page.request.physicalpath)
方法二:
string spath = system.web.httpcontext.current.request.mappath("images/")
//("images/")是当前虚拟目录下的任意目录
方法三:
string spath = page.server.mappath("images/"); //("images/")是当前虚拟目录下的任意目录
另:获取全路径中的文件名
string sfile = system.io.path.getfilename(sfile);
//获取当前进程的完整路径,包含文件名(进程名)。
string str = this.gettype().assembly.location;
result: x:xxxxxxxxx.exe (.exe文件所在的目录+.exe文件名)
//获取新的 process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。
string str = system.diagnostics.process.getcurrentprocess().mainmodule.filename;
相关文章
- asp.net获取当前url及来源url 09-04
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10