ASP.NET请求在此上下文中不可用

问题描述:

当我尝试打开网站时,出现此问题,我不知道它有什么问题。 我已编辑的堆栈跟踪它ASP.NET请求在此上下文中不可用

 
    Server Error in '/' Application. 

    Request is not available in this context 

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.Web.HttpException: Request is not available in this context 

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace 

    below. 

Stack Trace: 

    [HttpException (0x80004005): Request is not available in this context] 
     System.Web.HttpContext.get_Request() +8806688 
     labs.shared.config.CFGConstants.InitializeFromHttpContext() +42 
     labs.shared.config.CFGConstants..ctor() +722 
     labs.shared.config.CFGConstants.Get() +108 
     labs.site.framework.FWStateHelper.OnApplicationStart(HttpApplication app) +12 
     labs.site.Global.Application_Start(Object sender, EventArgs e) +5 

    [HttpException (0x80004005): Request is not available in this context] 
     System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +2724290 
     System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +128 
     System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +188 
     System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +295 
     System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +56 
     System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +231 

    [HttpException (0x80004005): Request is not available in this context] 
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8909915 
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85 
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333 
+0

这是否突然发生? – 2012-01-09 16:32:33

+0

有没有内部异常? – 2012-01-09 16:32:42

你一个可能在做事Application_Start事件处理程序。在IIS 7中,当时没有HttpRequest,您不应该依赖初始化应用程序的请求。

如果您确实需要在应用程序的使用寿命早期提出请求,那么您需要捕获第一个请求。

+0

我正在看帖子 http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start。 aspx 我相信它描述了同样的问题 感谢:) – 2012-01-09 16:38:41

+1

请记住,在IIS7中有一些机制可以在回收后强制运行应用程序,而不会发出请求。然后应用程序将启动,但请求可能不会很长时间到达。 – 2012-01-09 16:40:40

您可能要包括你似乎已经切断堆栈跟踪。描述很明显,请求无法用于您尝试使用它的地方。我怀疑你已经尝试访问Application_BeginRequest处理程序中的Request对象(我认为在Session和Request之类的事件被初始化之前调用了该对象)从你提供的堆栈跟踪中可以看出代码在Application_Start中尽管与上面相同,你在这里做什么?它可以在稍后阶段完成吗?它实际上从Request对象获得的信息是什么,获得一些其他的方式?

你肯定需要某种方式四处移动你的代码...