.NET会话不工作 [英] .NET Session not working
问题描述
这是一个奇怪的一个,但希望有人能在这里给我一个想法。我在我的应用程序将几个值到会话中的在session_start
的的Global.asax
。紧接着在session_start
我的基地页的的OnInit
被调用,并试图利用这些会话之一
变量。
This is a weird one, but hopefully someone can give me an idea here. I'm putting a few values into session in the Session_Start
of the Global.asax
in my app. Immediately after the Session_Start
my base page's OnInit
gets called and tries to use one of those Session
variables.
怪异的部分是有时它的工作原理,然后没有变化将开始给我这个错误:
The weird part is sometimes it works, and then after NO changes will start giving me this error:
会话状态只能用时
ENABLESESSIONSTATE
设置为真正
,
无论是在配置文件或
在页
指令。还请
确定
System.Web.SessionStateModule
或
自定义会话状态模块
包括在
<结构> \\<&的System.Web GT; \\<&的HttpModules GT;
在应用程序部分
配置。
"Session state can only be used when
enableSessionState
is set totrue
, either in a configuration file or in thePage
directive. Please also make sure thatSystem.Web.SessionStateModule
or a custom session state module is included in the<configuration>\<system.web>\<httpModules>
section in the application configuration."
我看了又看,发现上的web.config
启用会话的所有不同的方式。下面是它看起来像现在:
I've looked and looked finding all different ways on enabling session in the web.config
. Here is what it looks like now:
<system.web>
...
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
<xhtmlConformance mode="Legacy"/>
<pages>
<!-- enableSessionState="true" autoEventWireup="true" enableViewState="true" enableViewStateMac="true" -->
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpModules>
<!--<add name="Session" type="System.Web.SessionState.SessionStateModule"/>-->
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
您可以看到我有一些东西注释掉,特别是 ENABLESESSIONSTATE =真正的
和&LT;添加名称=会话类型= System.Web.SessionState.SessionStateModule/&GT;
,因为他们从来没有出现之前,它总是用来工作。但我跟他们试过同时启用,一方或另一方启用,它只是不有所作为。
You can see I have some stuff commented out, specifically the enableSessionState="true"
and <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
because they were never there before and it always used to work. But I've tried it with them both enabled, one or the other enabled, it just doesn't make a difference.
这是一个应用程序,一直在生产好几年了,我只是做轻微的变化,可能是其中最大的是增加一个标题栏页面,它和升级,从2.0到3.5。我还没有尝试添加 ENABLESESSIONSTATE
页面指令,因为它没有在工作的web.config
我不明白为什么它会直接工作在页面上,和我讨厌肮脏的应用起来了,或浪费了时间妄图使会话。
This is an app that has been in production for years, I'm only making minor changes, probably the biggest of which is adding a "titlebar" page to it, and upgrading from 2.0 to 3.5. I haven't tried adding the enableSessionState
to the page directives because it didn't work in the web.config
I don't see why it would work directly on the page, and I'd hate to dirty the app up anymore or waste anymore time trying in vain to enable session.
任何人有任何其他的想法?
Anyone have any other ideas?
谢谢,
杰夫
推荐答案
BREAKPOINTS!
BREAKPOINTS!
我有断点的基本页面的构造方法设置,并且主网页,还有在session_start和的OnInit。的同事,删除了所有断点调试器和问题dissappeared!
I had breakpoints set in the constructor methods of the base page, and the main page, as well as the Session_Start and the OnInit. A coworker deleted all breakpoints in the debugger and the problem dissappeared!
唉!
这篇关于.NET会话不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!