关于Server.MapPath()
时间:2007-04-17 来源:Narlon
今天见鬼了,想打开个文件“set.ini”都打不开。我建的是.net web的项目,我想想用"./conf/set.ini"不就ok了啊。。。结果不行。。。
我用File.exist()一看,果然不存在文件。。。
再用GetCurrentDirectory()一看,在D:\Microsoft Visual Studio 8\Common7\IDE,真见鬼了,我的项目在F盘啊。。。
郁闷。。。
后来baidu了半天终于找到了,用函数string Server.MapPath(string path)来得到相对应的物理文件路径
我们来看看它的作用
string Server.MapPath(string path)
返回与Web服务器上的指定虚拟路径相对应的物理文件路径。
<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>
<%= Server.MapPath("/")%>
<%= Server.MapPath("")%>
<%=Server.MapPath(".")%>
<%= Server.MapPath("../")%>
<%= Server.MapPath("..")%>
以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
运行结果:
C:\Inetpub\wwwroot\EnglishClub\manage\WebForm1.aspx
C:\Inetpub\wwwroot\
C:\Inetpub\wwwroot\EnglishClub\manage
C:\Inetpub\wwwroot\EnglishClub\manage
C:\Inetpub\wwwroot\EnglishClub\
C:\Inetpub\wwwroot\EnglishClub
为这搞了一下午。。。。。。。。。些下来纪念一下。。。
我用File.exist()一看,果然不存在文件。。。
再用GetCurrentDirectory()一看,在D:\Microsoft Visual Studio 8\Common7\IDE,真见鬼了,我的项目在F盘啊。。。
郁闷。。。
后来baidu了半天终于找到了,用函数string Server.MapPath(string path)来得到相对应的物理文件路径
我们来看看它的作用
string Server.MapPath(string path)
返回与Web服务器上的指定虚拟路径相对应的物理文件路径。
<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>
<%= Server.MapPath("/")%>
<%= Server.MapPath("")%>
<%=Server.MapPath(".")%>
<%= Server.MapPath("../")%>
<%= Server.MapPath("..")%>
以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
运行结果:
C:\Inetpub\wwwroot\EnglishClub\manage\WebForm1.aspx
C:\Inetpub\wwwroot\
C:\Inetpub\wwwroot\EnglishClub\manage
C:\Inetpub\wwwroot\EnglishClub\manage
C:\Inetpub\wwwroot\EnglishClub\
C:\Inetpub\wwwroot\EnglishClub
为这搞了一下午。。。。。。。。。些下来纪念一下。。。
相关阅读 更多 +