Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 435
Michal B. Avatar asked May 03 '13 12:05

Michal B.


People also ask

How do I get the root path in .NET core?

The Application Base (Root) path is available in the ContentRootPath property of the interfaces IHostingEnvironment (. Net Core 2.0) and IWebHostEnvironment (. Net Core 3.0) in ASP.Net Core. The IHostingEnvironment is an interface for .

What is root in asp net?

By default, the wwwroot folder in the ASP.NET Core project is treated as a web root folder. Static files can be stored in any folder under the web root and accessed with a relative path to that root.


1 Answers

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.

like image 94
cgijbels Avatar answered Sep 21 '22 06:09

cgijbels