首页 文章

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

提问于
浏览
3

当我尝试打开网站时,我遇到了这个问题,我不知道它有什么问题 . 我用它编辑了堆栈跟踪

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

2 回答

  • 0

    您可能正在 Application_Start 事件处理程序中执行操作 . 在IIS 7中, there is no HttpRequest available at that time ,您不应该依赖于初始化应用程序的请求 .

    如果您确实需要在应用程序的生命周期早期请求内容,则需要捕获第一个请求 .

  • 14

    您可能希望包含您似乎已切断的堆栈跟踪 . 描述非常明显,在您尝试使用Request的地方无法使用Request . 我怀疑你已经尝试访问 Application_BeginRequest 处理程序中的Request对象(我认为在Session和Request之类的东西被初始化之前被调用 . 我认为 Application_AcquireRequestState 是最早的Request可用...

    从您提供的堆栈跟踪中看出代码在 Application_Start 中,尽管与上面相同 . 你想在这做什么?可以在以后阶段完成吗?从Request对象实际获得的是什么,可以通过其他方式获取该信息吗?

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

相关问题