How to get the physical location of an ASP.NET web application without using HttpContext.Current?

前端 未结 2 1384
天涯浪人
天涯浪人 2020-12-10 17:19

I\'ve found myself having a requirement to configure log4net based on a file relative to the physical location of the running ASP.NET web application. We like to start the l

相关标签:
2条回答
  • 2020-12-10 17:36

    Try HttpRuntime.AppDomainAppPath. For more info, read IIS7 Integrated mode: Request is not available in this context exception in Application_Start posted by Mike Volodarsky.

    0 讨论(0)
  • 2020-12-10 17:41

    As an alternative answer to my own question, I'd like to add that Server.MapPath() works during the Application_Start event as well. The application domain path would then be equal to Server.MapPath("~"), but it's handier for mapping relative paths, removing the burden of concatenation (what MapPath was meant for to begin with).

    0 讨论(0)
提交回复
热议问题