Similar to Ubiquitous way to get the root directory an application is running in via C#, but that question seems to be related to W开发者_开发知识库in Forms. How would the same be done for Web Forms?
I was using...
HttpContext.Current.Server.MapPath("~")
This works great for handling HTTP requests but seems not to work if a scheduler like Quartz.NET invokes a job (the problem I am having). The HttpContext.Current
is null in that scenario since an actual HTTP request is not made.
You're looking for the HttpRuntime.AppDomainAppPath
property, and perhaps the VirtualPathUtility
class.
Try the System.Web.Hosting.HostingEnvironment.MapPath
method. AFAIK it's not dependent on HttpContext so you should be able to use it from a background thread.
Use AppDomain.CurrentDomain.BaseDirectory
. This corresponds to AppDomainSetup.ApplicationBase
which states that it is 'The name of the application base directory.'
http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx
http://msdn.microsoft.com/en-us/library/system.appdomainsetup.applicationbase.aspx
精彩评论