經過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