asp.net应用程序中的会话状态enableSessionState问题
生产环境出现如下错误
仅当在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态。另请确保应用程序配置中的configuration\system.web\httpModules 部分中包含System.Web.SessionStateModule 或自定义会话状态模块。
到目前为止,我已尝试过以下操作
- 检查
machine.config
和web.config
,两者都有enableSessionState="true"
- 添加
enableSessionState="true"
到web.config
中的页面 - 状态模块也添加到
部分 - 甚至尝试设置
enableSessionState="true “
在页面指令中
注意:当我尝试在开发环境中调试代码,一切正常。
谁能帮我解决这个问题,我只是想不出解决办法。
I get the following error in the production environment
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the configuration\system.web\httpModules section in the application configuration.
The following things I have tried as of now
- Checked
machine.config
andweb.config
, both haveenableSessionState="true"
- Added
enableSessionState="true"
to pages inweb.config
- State module is also added in
<httpmodules>
section - Even tried setting
enableSessionState="true"
in page directive
Note: When I try to debug the code in Dev environment, everything works fine as it should.
Can anyone help me out getting over this issue, I just can't figure out a way out of it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的会话状态配置是什么样的?您可能希望设置为使用 inproc 会话处理。
http://msdn.microsoft.com/en-us/library/ms178586.aspx
What does your session state config look like? You probably want to be set up to use inproc session handling.
http://msdn.microsoft.com/en-us/library/ms178586.aspx
我知道这是一个迟到的回复,但我只想补充一下我如何解决同样的问题。
首先我想强调,我使用的是 Web 表单,而不是 MVC - 这可能不适用于 MVC。
我创建了一个包含类 ContactUser 的 Web 表单,并创建了自己的构造函数,因此它看起来像:
public ContactUser(String to, bool isUser)
{
...
}
在此我尝试访问会话变量:
String user = Session["username"]
事实证明,您不能使用会话状态类的构造函数,但您可以在您编写的其他函数以及 protected void Page_Load(object sender, EventArgs e) 过程中使用它。因此,一旦我将会话状态从构造函数移到页面加载过程中,一切就正常了:)!
希望这对遇到同样问题的人有所帮助:D!
I know this is a late response but I just want to add how I fixed the same problem.
First I want to emphasize that I'm using web forms, not MVC - this may not work for MVC.
I created a web form that contained the class ContactUser and I created my own constructor so it looked like:
public ContactUser(String to, bool isUser)
{
...
}
And in this I tried to access a session variable:
String user = Session["username"]
It turns out that you CANNOT use the session state in the constructor of a class, but you can use it in other functions that you write and in the protected void Page_Load(object sender, EventArgs e) procedure. So once I moved session state out of the constructor into the page load procedure everything worked :)!
Hope this helps anyone that runs into the same problem :D!