A universal way to get the root file system from the .NET WEB application

It seems like an All-Local way to get the root directory where the application works through C # , but this question seems to be related to Win Forms. How to do the same for web forms?

I used...

HttpContext.Current.Server.MapPath("~") 

This works fine for handling HTTP requests, but it doesn't seem to work if a scheduler like Quartz.NET is causing the task (I have a problem). HttpContext.Current is null in this scenario because the actual HTTP request has failed.

+6
c # webforms
source share
3 answers

You are looking for the HttpRuntime.AppDomainAppPath property, and possibly VirtualPathUtility .

+5
source share

Try the System.Web.Hosting.HostingEnvironment.MapPath method. AFAIK is independent of HttpContext, so you should use it from a background thread.

+5
source share

Use AppDomain.CurrentDomain.BaseDirectory . This corresponds to AppDomainSetup.ApplicationBase , which states that this is the "Application Base Directory Name".

http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx

http://msdn.microsoft.com/en-us/library/system.appdomainsetup.applicationbase.aspx

0
source share

All Articles