会话状态在这种情况下不可用-在Global.asax中 [英] Session State Not Available In This Context - In Global.asax

查看:303
本文介绍了会话状态在这种情况下不可用-在Global.asax中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到在此上下文中不可用的会话状态"错误.

I am getting a 'session state not available in this context' error.

该错误嵌套在Global.asax文件中许多方法的sender参数中:

The error is nested in the sender parameter of a number of methods within the Global.asax file:

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Session_Start
  • Application_Error

该错误发生在页面加载的第一页(以及随后的所有页面加载).

The error happens on the very first page load (and all page loads thereafter).

我已经在项目中添加了一个全新的空白页面WebForm1.aspx,并将其作为我的起始页面.

I've added a completely new and empty page, WebForm1.aspx, to the project and made it my start page.

您会认为在空白页上没有任何问题.据我所知,在加载一个空页面时,没有执行我的代码.但是我仍然收到会话状态错误.

You'd think nothing could go wrong on an empty page. No code of mine is executed, as far as I can see, when loading an empty page. But I'm still getting the session state error.

我的项目完全正常.没有显示错误页面.任何时候都没有不正确的行为.

My project works totally fine. No error pages are shown. There is no incorrect behavior at any time.

但是这个会话错误显示在我当前项目的sender参数中的事实困扰着我.在空白的新项目中不会生成此错误.

But the fact that this session error shows up in the sender parameter of my current project bugs me. This error is not generated in a blank, new project.

在我当前的项目中,此错误可能是什么原因造成的?

What can possibly be the cause of this error in my current project?

如何跟踪错误发生的位置?我无法在后台的ASP.NET代码中设置断点.或者可以吗?

How can I trace where the error occurs? I can't set breakpoints in ASP.NET code that's under the hood. Or can I?

这是我的会话配置:

<pages enableSessionState="true" />
<sessionState mode="InProc" cookieless="false" timeout="20" />

更新:

我刚刚发现,一个全新的空白项目在发送方对象中也存在此错误.在Application_BeginRequest和Application_AuthenticateRequest方法中可见.但是空白项目不会像其他项目那样生成Application_Error事件.

I just found out that a brand new blank project also has this error in the sender object. It's visible in the Application_BeginRequest and Application_AuthenticateRequest methods. But the blank project isn't generating the Application_Error event, like my other project is.

推荐答案

您在周期中过早请求会话状态.您需要在 Application_AcquireRequestState

You are requesting for session state too early in the cycle. you need to do it in Application_AcquireRequestState

这篇关于会话状态在这种情况下不可用-在Global.asax中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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