的HttpContext中不工作的global.asax.cs [英] HttpContext does not work in global.asax.cs

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

问题描述

我有这个code在的global.asax.cs

 保护无效的Application_Start(对象发件人,EventArgs的)
{
    字符串LOGFILE = HttpContext.Current.Request.PhysicalApplicationPath +log4net.config;
}
 

它工作正常,在.NET 4.0中,但抛出以下异常使用.NET 4.5的时候。

  

请求不可用在这种情况下

解决方案

错误似乎pretty的清晰 - 在要求的对象是不是在这种情况下使用

尝试

  HttpRuntime.AppDomainAppPath
 

 使用Server.Mappath(。)
 

来代替。

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";
}

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

解决方案

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

Try

HttpRuntime.AppDomainAppPath 

or

Server.MapPath(".")

instead.

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

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