如何在asp.net网站上设置一个多小时的会话

时间:2016-03-03 11:33:07

标签: c# asp.net session c#-4.0 session-state

我试图在asp.net网站上设置超过一小时的会话。我正在使用iss7运行网站。我也在web.config中设置了会话状态超时3600但是在10分钟会话期满也在我尝试在iis服务器中设置但是无法完成设置

   ** its my web.config**

标题

     <!-- language: c# -->


         <configuration>
              <system.web.extensions>        <scripting>
                  <webServices>
                    <jsonSerialization maxJsonLength="50000000"/>          </webServices>
                </scripting>
              </system.web.extensions>
               <system.webServer>
                 <handlers>
                   <remove name="ChartImageHandler"/>
                   <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd"
         type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
         System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral,
         PublicKeyToken=31bf3856ad364e35"/>
                 </handlers>
               </system.webServer>
               <appSettings>
                 <add key="ConnectionString" value=""/>
                 <add key="AdminRole" value="Company-Admin"/>
                 <add key="ApproverRole" value="Approver"/>
                 <add key="StaffRole" value="Staff"/>
                <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;"/>
               </appSettings>
               <connectionStrings>

                 <add name="ConnectionString" connectionString="" providerName="System.Data.SqlClient"/>
                <add name="ConnectionStringDBePay_14_15" connectionString="" providerName="System.Data.SqlClient"/>
               </connectionStrings>       <system.web>


                 <trace enabled="true" mostRecent="true" />
                 <pages>
                   <controls>
                     <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
         assembly="System.Web.DataVisualization, Version=4.0.0.0,
         Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                   </controls>
                 </pages>
                 <customErrors defaultRedirect="~/Error.aspx" mode="Off" />
                 <compilation debug="true" targetFramework="4.0">
                   <assemblies>
                     <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                     <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                     <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                     <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                   </assemblies>
                 </compilation>
                 <authentication mode="Forms">
                   <forms loginUrl="Default.aspx" protection="All" timeout="80200" name="MCSSCookie" requireSSL="false"
         slidingExpiration="true" cookieless="AutoDetect"
         enableCrossAppRedirects="false"/>
                 </authentication>
                 <httpRuntime executionTimeout="999999" maxRequestLength="1024000" />
                 <sessionState timeout="3600"></sessionState>
                 <membership defaultProvider="AspNetSqlMembershipProviderRelaxed">
                   <providers>
                     <clear/>
                     <add connectionStringName="ConnectionString" passwordAttemptWindow="10" enablePasswordRetrieval="true"
         enablePasswordReset="true" requiresQuestionAndAnswer="true"
         applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear"
         maxInvalidPasswordAttempts="15" passwordStrengthRegularExpression=""
         minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0"
         name="AspNetSqlMembershipProviderRelaxed"
         type="System.Web.Security.SqlMembershipProvider, System.Web,
         Version=2.0.3500.0, Culture=neutral,
         PublicKeyToken=b03f5f7f11d50a3a"/>
                   </providers>
                 </membership>
                 <profile>
                   <providers>
                     <clear/>
                     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider"
         connectionStringName="ConnectionString" applicationName="/"/>
                   </providers>
                 </profile>
                 <roleManager enabled="true">
                   <providers>
                     <clear/>
                     <remove name="AspNetSqlRoleProvider"/>
                     <add name="AspNetSqlRoleProvider" connectionStringName="ConnectionString" applicationName="/"
         type="System.Web.Security.SqlRoleProvider, System.Web,
         Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                   </providers>
                 </roleManager>
               </system.web>
             </configuration>

2 个答案:

答案 0 :(得分:1)

像这样设置会话超时。请试一试。

<configuration>
   <system.web>
       <sessionState timeout="61"></sessionState>
   </system.web>
</configuration>

查看官方会话状态docs

答案 1 :(得分:0)

如下更新您的Web配置。

<configuration>
   <system.web>
   <sessionState mode="InProc" cookieless="false" timeout="10" /> 
   </system.web>
</configuration>