protected void Page_Load(object sender, EventArgs e)
{
string path = HttpContext.Current.PhysicalApplicationPath;
// C:\inetpub\wwwroot\
// Which is the same as:
HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;
string path = request.PhysicalApplicationPath;
}
If you aren't processing a page request, you can use HttpRuntime.AppDomainAppPath.
protected void Application_Start(object sender, EventArgs e)
{
string path = HttpRuntime.AppDomainAppPath;
// C:\inetpub\wwwroot
}
If you attempt to access HttpContext.Current.Request in the above example, ASP.NET will throw an exception: "Request is not available in this context"