2012-08-01 76 views
3

我在ASP.NET頁面內部實現了一個Web方法來執行異步調用。現在我需要知道我的web應用程序的物理應用程序路徑。從Web方法內部查找應用程序路徑

我通常使用Request.PhysicalApplicationPath,但是如何從Web方法中獲取相同的信息?

注意沒有RequestServer屬性可用的Web方法裏面......

+1

也許下面的工作:HttpContext.Current.Request.MapPath( HttpContext.Current.Request.ApplicationPath)。或者也許HttpContext.Current.Request.PhysicalApplicationPath。 – Tom 2012-08-01 09:19:31

回答

4

我一直使用:

var rootPath = HostingEnvironment.ApplicationPhysicalPath; 

,您需要在您的類指令還添加using System.Web.Hosting;

+0

完美!非常感謝你。 – davioooh 2012-08-01 15:04:30

1

您是否嘗試過使用Server.MapPath("/")

編輯:

或許System.Web.Hosting.HostingEnvironment.MapPath()

+0

沒有'Request'或'Server'屬性在Web方法內可用... – davioooh 2012-08-01 09:15:47

+0

道歉,我習慣於使用具有HttpContext可用的服務。看我的編輯。 – 2012-08-01 09:23:44

0
AppDomain.CurrentDomain.BaseDirectory 
相關問題