How do you determine the physical path of a file without an HttpContext?

Matt picture Matt · Aug 23, 2010 · Viewed 16.1k times · Source

I have some processes that run without an HttpContext in an ASP.NET MVC web application. This process needs to be able to determine the physical path to the Contents directory of the application for reading/writing data. But, since it is without an HttpContext, I don't get to use fancy things like Server.MapPath and such. Suggestions?

Answer

Abel picture Abel · Aug 23, 2010

In a website, it is best to use HttpRuntime.AppDomainAppPath, because in certain moments of the execution path (i.e. when the site starts up), there's no HttpContext.Current available.

See also this post.