[ASP.NET]尋找檔案位置

[ASP.NET]尋找檔案位置

前言

今天發覺為什麼感覺每次我取得檔案位置方法,都不一樣,是錯覺嗎???? 不是是我從來都沒好好整理,所以今天使用到他,就直接一點整理一下杯。
版本:VS2010

範例網址

位址:http://localhost:3333/notebook/aspnet/aspnet002000.aspx/123?aa=123

語 法 結 果
System.Web.Hosting.HostingEnvironment.MapPath("~") D:\local_web\notebook
Server.MapPath("~") D:\local_web\notebook
My.Request.PhysicalApplicationPath D:\local_web\notebook\
System.IO.Path.GetDirectoryName(My.Request.PhysicalPath) D:\local_web\notebook\aspnet
My.Request.PhysicalPath D:\local_web\notebook\aspnet\aspnet002000.aspx
System.IO.Path.GetFileName(My.Request.PhysicalPath) aspnet002000.aspx
Page.ResolveClientUrl("~") ../../
Page.ResolveUrl("~") /notebook/
My.Request.ApplicationPath /notebook
My.Request.Path /notebook/aspnet/aspnet002000.aspx/123
My.Request.RawUrl /notebook/aspnet/aspnet002000.aspx/123?aa=123
My.Request.CurrentExecutionFilePath /notebook/aspnet/aspnet002000.aspx
My.Request.CurrentExecutionFilePathExtension .aspx
My.Request.AppRelativeCurrentExecutionFilePath ~/aspnet/aspnet002000.aspx
My.Request.Url.AbsolutePath /notebook/aspnet/aspnet002000.aspx/123
My.Request.Url.AbsoluteUri http://localhost:3333/notebook/aspnet/aspnet002000.aspx/123?aa=123
My.Request.Url.Scheme http
My.Request.Url.Authority localhost:3333
My.Request.Url.Host localhost
My.Request.Url.Port 3333
My.Request.Url.PathAndQuery /notebook/aspnet/aspnet002000.aspx/123?aa=123
My.Request.Url.LocalPath /notebook/aspnet/aspnet002000.aspx/123
Join(My.Request.Url.Segments, " ") / notebook/ aspnet/ aspnet002000.aspx/ 123
My.Request.PathInfo /123
My.Request.Url.Query ?aa=123

結語

取得檔案位置方法還真多,重複也很多,有沒有影響沒實驗過,如果有建議的,請多多指教謝謝。

Louis的標籤: