2013-08-16 26 views
1

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

檢查.. –

+0

你的會話狀態模式是什麼?它是Inproc /狀態服務器/ SQL? – Thomas

+0

托馬斯,你能解釋你的答案嗎? – benhi

回答

0

請您啓用了部分會話狀態以及在配置

<system.web> 
     <pages enableSessionState="true"> 
</system.web> 

,或者如果它未設置爲網頁上假的,你可以添加此頁面

<%@Page enableSessionState="true"> 
+0

我試過了,但它不起作用。 我得到同樣的錯誤。 – benhi

+0

ASP.NET會話狀態管理器服務服務正在運行? –

+0

我只有ASP.NET狀態服務,並且正在運行... – benhi