How to get application root (full physical path) in OnApplicationStarted in MVC3 application?
Asked Answered
P

2

11

Until now I used:

Dim appPath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath)

But today I moved my app from IIS6 to IIS7 and I get "Request is not available in this context" exception. This is due to Integrated mode pipeline in IIS7. I do not want to go to classic mode, so I am looking for a different way of getting the application path (which is "C:\SVN\L2E\trunk\Website").

Does anyone have an idea how I can get the full physical path of my MVC3 app?

Pappus answered 3/5, 2013 at 12:13 Comment(0)
H
18

You can use System.Web.HttpRuntime.AppDomainAppVirtualPath to get the virtual path and call System.Web.Hosting.HostingEnvironment.MapPath to map the virtual path to a physical one.

Holmen answered 29/5, 2013 at 12:37 Comment(1)
Thanks, works as it should :). Strange I could not find it myselfPappus
S
18

use this:

 AppDomain.CurrentDomain.BaseDirectory 
Silden answered 13/8, 2014 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.