HttpContext 在 global.asax.cs 中不起作用 [英] HttpContext does not work in global.asax.cs

查看:31
本文介绍了HttpContext 在 global.asax.cs 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 global.asax.cs 中有这个代码

I have this code in the global.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
    string logFile = HttpContext.Current.Request.PhysicalApplicationPath + "log4net.config";
}

它在 .NET 4.0 中运行良好,但在 .NET 4.5 中使用时抛出以下异常.

It works fine in .NET 4.0, but throws the following exception when using in .NET 4.5.

请求在此上下文中不可用

Request is not available in this context

推荐答案

错误似乎很明显 - Request 对象在该事件中不可用.

Error seems pretty clear - the Request object is not available in that event.

试试

HttpRuntime.AppDomainAppPath 

Server.MapPath(".")

相反.

这篇关于HttpContext 在 global.asax.cs 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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