asp.net 文件路徑之獲得虛擬目錄的網(wǎng)站的根目錄
更新時(shí)間:2012年10月08日 22:13:32 作者:
asp.net下獲取文件路徑常用代碼,獲得虛擬目錄的網(wǎng)站的根目錄
string Server.MapPath(string path)
返回與Web服務(wù)器上的指定虛擬路徑相對(duì)應(yīng)的物理文件路徑。
Server.MapPath(Request.ServerVariables["PATH_INFO"])
Server.MapPath("/")
Server.MapPath("")
Server.MapPath(".")
Server.MapPath("../")
Server.MapPath("..")
Page.Request.ApplicationPath
(HttpContext.Current.Request.PhysicalApplicationPath);
以上的代碼在http://localhost/EnglishClub/manage/WebForm1.aspx頁面
運(yùn)行結(jié)果:
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
C:\Inetpub\wwwroot\EnglishClub\
由以上可以知道:
要想獲得要是建立的虛擬目錄的網(wǎng)站的根目錄可以這樣使用:
Server.MapPath(Page.Request.ApplicationPath)
返回與Web服務(wù)器上的指定虛擬路徑相對(duì)應(yīng)的物理文件路徑。
Server.MapPath(Request.ServerVariables["PATH_INFO"])
Server.MapPath("/")
Server.MapPath("")
Server.MapPath(".")
Server.MapPath("../")
Server.MapPath("..")
Page.Request.ApplicationPath
(HttpContext.Current.Request.PhysicalApplicationPath);
以上的代碼在http://localhost/EnglishClub/manage/WebForm1.aspx頁面
運(yùn)行結(jié)果:
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
C:\Inetpub\wwwroot\EnglishClub\
由以上可以知道:
要想獲得要是建立的虛擬目錄的網(wǎng)站的根目錄可以這樣使用:
Server.MapPath(Page.Request.ApplicationPath)
相關(guān)文章
在Asp.net下實(shí)現(xiàn)變長連接的web即時(shí)應(yīng)用的實(shí)現(xiàn)范例及ReverseAjax的演示介紹
根據(jù)公司近期的一個(gè)培訓(xùn)整理的資料,附件包括一個(gè)完整的使用變長連接的web即時(shí)聊天室的范例和針對(duì)ReverseAjax的ppt培訓(xùn)文稿,其中ppt中包含了對(duì)范例程序的完整講解2011-12-12
Silverlightbutton圖片切換樣式實(shí)例代碼
這篇文章介紹了Silverlightbutton圖片切換樣式實(shí)例代碼,有需要的朋友可以參考一下2013-11-11
ASP.net 動(dòng)態(tài)加載控件時(shí)一些問題的總結(jié)
經(jīng)常見到有人說在ASP.net中不要使用動(dòng)態(tài)控件,我想主要的原因在于使用動(dòng)態(tài)控件會(huì)帶來一些問題,在做項(xiàng)目的過程中,我將由動(dòng)態(tài)加載控件引發(fā)的總是作了一個(gè)小小的總結(jié).2009-04-04
asp.net中使用自定義控件的方式實(shí)現(xiàn)一個(gè)分頁控件的代碼
在web開發(fā)中,常常需要顯示一些數(shù)據(jù),而為了方便排版及瀏覽,我們只需要顯示所有記錄中的一部分。一般情況下,我們采用分頁來實(shí)現(xiàn)這個(gè)需求2012-10-10
ASP.NET MVC分頁和排序功能實(shí)現(xiàn)
這篇文章主要介紹了MVC學(xué)習(xí)系列之分頁和排序功能實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07

