Similar to Ubiquitous way to get the root directory an application is running in via C#, but that question seems to be related to Win 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.
Right-click the Web application you want more information about, such as SharePoint (80), and then click Properties. In the Default Web Site Properties window, click the Home Directory tab. The Local Path field in this tab shows the Web application root folder.
The Application Base (Root) path is available in the ContentRootPath property of the interfaces IHostingEnvironment (. Net Core 2.0) and IWebHostEnvironment (. Net Core 3.0) in ASP.Net Core. The IHostingEnvironment is an interface for .
In windows the root folder would be the desktop. Desktop->Computer->C:\folder1\folder2 with the IShellFolder Interface.
Right-click the directory that you want to mark as an application root, and then click Properties. On the Directory tab, in the Application Settings section, click Create. In the Application name text box, type the name of the application, and then click OK. The virtual directory is now an application root.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With