经过Google的大量研究,我还没有找到解决我的问题的方法。如何使用会话变量?
当我想要的值保存到会话变量,一切正常:
Session["idResult"] = youthID;
但是当我想用下面的代码行的值:
youthID = (int)Session["idResult"];
我获取错误:只有在配置文件或Page指令中将enableSessionState设置为true时,才能使用会话状态。请确保System.Web.SessionStateModule或自定义会话状态模块包含在应用程序配置的<configuration>\<system.web>\<httpModules>
部分中。
我试着将它添加到web.config:EnableSessionState="True"
也:
<httpModules><add name="Session" type="System.Web.SessionState.SessionStateModule"/> </httpModules>
和许多其他的可能性,但它不工作
我的默认web.config是:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
检查.. –
你的会话状态模式是什么?它是Inproc /状态服务器/ SQL? – Thomas
托马斯,你能解释你的答案吗? – benhi