1

For you what is the best way to do that? I would like that all the pages of my app have timeout of 20 minutes but 4. I would like these 4 pages have 60 minutes timeout..

What is the best way?Have I to set the Session.timeout in the constructor of the pages? Is there any other way?

Thanks

bAN
  • 13,375
  • 16
  • 60
  • 93

3 Answers3

4

You could create a custom base page (that inherits from System.Web.UI.Page), set the session timeout in the Page_Init handler, and then set those four pages to inherit from your custom base page. That gives you one place to manage the session timeout value.

Ken Pespisa
  • 21,989
  • 3
  • 55
  • 63
  • Thanks, I was thinking put instructions in the constructor, but that was a bad idea, OnInit event is best one! :-) – bAN Jun 24 '11 at 07:40
1

You can configure this through web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <sessionState timeout="20"/>
  <location path="Page1.aspx">
    <system.web>
      <sessionState timeout="60"/>
    </system.web>
  </location>
  <location path="Page2.aspx">
    <system.web>
      <sessionState timeout="60"/>
    </system.web>
  </location>
  <location path="Page3.aspx">
    <system.web>
      <sessionState timeout="60"/>
    </system.web>
  </location>
</configuration>
pseudocoder
  • 4,314
  • 2
  • 25
  • 40
1

Be sure to set the idle timeout for the application pool as well:

http://weblogs.asp.net/aghausman/archive/2009/02/20/prevent-request-timeout-in-asp-net.aspx

According to the docs, you can set the timeout at anytime. Of course it has to be while during a request to the server! :-)

You could implement a custom Page attribute, like:

using System;
System.Web.SessionState;

public class TimeoutControlPage: System.Web.UI.Page {
    public int Timeout {
        get { return Session.Timeout; }    
        set { Session.Timeout = value; }
   }

}

and then save the below page as "test.aspx":

<%@ Page Language="C#" Timeout="60"  Inherits="TimeoutControlPage" %>

<html>
   <body>

   </body>
</html>
dcorbett
  • 171
  • 1
  • 2