如何在不使用 HttpContext.Current 的情况下获取 ASP.NET Web 应用程序的物理位置? [英] How to get the physical location of an ASP.NET web application without using HttpContext.Current?

查看:23
本文介绍了如何在不使用 HttpContext.Current 的情况下获取 ASP.NET Web 应用程序的物理位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己需要根据与正在运行的 ASP.NET Web 应用程序的物理位置相关的文件来配置 log4net.我们喜欢尽可能早地启动记录器,所以 Application_Start 似乎是一个合适的地方.在 IIS6 中,这运行良好并且已经运行了很长时间,但现在我们转移到 IIS7,这将不再起作用:

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 logger as early as possible, so Application_Start seems a proper place. In IIS6, this works fine and has been running for ages, but now we moved to IIS7 and this won't work anymore:

string absolutePath = HttpContext.Current.Request.PhysicalApplicationPath;

因为 HttpContext.Current 在许多 global.asax(应用程序、会话)事件中不可用.这是旧闻,我们都知道它引发了现在臭名昭著的 请求在此上下文中不可用错误.我们不想回到经典模式.

because the HttpContext.Current is not available in many global.asax (Application, Session) events. This is old news, we all know it raises the now infamous Request is not available in this context error. We don't want to move back to Classic Mode.

现在,问题很简单:不使用HttpContext,是否可以找到当前正在运行的Web应用程序实例的物理位置?

Now, the question is simple: without using HttpContext, is it possible to find the physical location of the currently running web application instance?

推荐答案

尝试 HttpRuntime.AppDomainAppPath.有关更多信息,请阅读 IIS7 集成模式:Mike Volodarsky 发布的 Application_Start 中的请求在此上下文异常中不可用.

这篇关于如何在不使用 HttpContext.Current 的情况下获取 ASP.NET Web 应用程序的物理位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆