Sometimes you might need to know where your application is running, for instance if you want to open a file relative to that position. With desktop apps this is more straightforward but web applications run within IIS and any attempt to navigate to a relative path will fail because you start out within a directory from the IIS webserver.
Here is quick way to find out where you're application is running:
public static string GetFullApplicationPath()
{
return HttpRuntime.AppDomainAppVirtualPath != null ? HttpRuntime.AppDomainAppPath : Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
This method works for web applications and desktop applications. It tests if it is a web application and if so it returns the AppDomainAppPath property. Else it returns the Assembly.location property.