When you start off by telling those who disagree with you that they are not merely in error but in sin, how much of a dialogue do you expect? --Thomas Sowell
NinjaTrader Kickstart - Use your dev skills to trade the markets. This is my latest free course. I hope you'll try it out - Steve @ CambiaResearch

How do I get the application path in an ASP.NET application?

And convert it from a virtual path to a physical path

The Question

How do I get the application path in an ASP.NET application?

Retrieve the application path
string appPath = HttpContext.Current.Request.ApplicationPath;

This property returns the virtual application path.

An empty string indicates that the application is at the root of the website.

Other examples might be:

  • /c4
  • /myapplication
  • /myapps/AppNumberOne
Convert virtual application path to a physical path
string physicalPath = HttpContext.Current.Request.MapPath(appPath);

Examples:

  • C:\inetpub\wwwroot\myweb\c4
  • C:\inetpub\wwwroot\myweb\myapplication
  • C:\inetpub\wwwroot\myweb\myapps/AppNumberOne
 

Version: 5.1.20191022.2156