Web.config session timeout

Discussion in 'ASP .Net' started by steph_mw@hotmail.com, Feb 21, 2006.

  1. Guest

    I have a web application and when a user opens the application (using
    windows integration) and loads some data, it loads a ID number into the
    session state. If for some reason they go away from their PC and come
    back after 20 mintes they are receiving an error.

    This error relates to the fact that the session has timed out and all
    session variables have been cleared. The only issue I have with this is
    that the session timeout is set to 24 hours (1440 minutes). I
    understand that this is the maximum value.

    <sessionState mode="InProc"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="1440" />

    We have no issue with the session variables been open this long as the
    server has available memory.

    Can anyone help me with this issue or point me in the right direction.

    TIA
    Stephen
    , Feb 21, 2006
    #1
    1. Advertising

  2. Not sure why the session times out even if you set it to 1440 but i have a
    good solution for you.

    The idea is to send an aspx request to renew session every 10 minutes with
    javascript code. So if user has browser open the session will never time
    out. If browser closed session will timeout after 20 seconds.

    See code below.

    Step 1.
    The code for renewSes.aspx.cs. You must not have any HTML in renew.aspx
    file.

    public class renewSes : System.Web.UI.Page

    {

    static byte [] gif =
    {0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0x91,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x09,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x08,0x04,0x00,0x01,0x04,0x04,0x00,0x3b,0x00};

    #region Web Form Designer generated code

    override protected void OnInit(EventArgs e)

    {

    InitializeComponent();

    base.OnInit(e);

    }




    private void InitializeComponent()

    {

    Response.AddHeader("ContentType", "image/gif");

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Response.BinaryWrite(gif);

    Response.End();

    }

    #endregion

    }





    Step2.

    Each page must have following script in the beginning

    <script language="Javascript">

    window.setInterval("renewSession()", 600000);

    function renewSession()

    {

    document.images("renewSession").src = /renewSes.aspx?par=" + Math.random();

    }

    </script>

    Step3.

    Each page must have somewhere in HTML

    <IMG name="renewSession" height=1 src="/images/transparentpixal.gif" width=1
    border=0>

    You can grab transparentpixal.gif from
    http://www.cardone.com/English/Club/images/transparentpixal.gif

    -------------------------------------------------------------------------------------------------------------

    For step2 and step 3 I usually create UserControl that does in a code in
    Init method

    Page.RegisterClientScriptBlock("renewSession", "<script
    language=\"Javascript\">\r\n" +

    "window.setInterval(\"renewSession();\", 600000);\r\n" +

    "function renewSession()\r\n" +

    "{document.images(\"renewSession\").src = \"/renewSes.aspx?par=\" +
    Math.random();}\r\n" +

    "</script>\r\n");

    And HTML has that line with <IMG tag>

    Then all you need to do is to drop that control on each page in your
    project.

    George.



    <> wrote in message
    news:...
    >I have a web application and when a user opens the application (using
    > windows integration) and loads some data, it loads a ID number into the
    > session state. If for some reason they go away from their PC and come
    > back after 20 mintes they are receiving an error.
    >
    > This error relates to the fact that the session has timed out and all
    > session variables have been cleared. The only issue I have with this is
    > that the session timeout is set to 24 hours (1440 minutes). I
    > understand that this is the maximum value.
    >
    > <sessionState mode="InProc"
    > stateConnectionString="tcpip=127.0.0.1:42424"
    > sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    > cookieless="false"
    > timeout="1440" />
    >
    > We have no issue with the session variables been open this long as the
    > server has available memory.
    >
    > Can anyone help me with this issue or point me in the right direction.
    >
    > TIA
    > Stephen
    >
    George Ter-Saakov, Feb 21, 2006
    #2
    1. Advertising

  3. Guest

    Thanks George for your solution.

    However I would like to know why it still times out when the timeout
    value is stored in the web.config file. If anyone can shed some light
    on this it'd be appreciated.

    Thanks
    Stephen
    , Feb 21, 2006
    #3
  4. Do not really know answer to your question.
    May be you set to high. May be it can not be more than couple hours and
    resets itself to default if you try to set it to high.

    Try to set it to 60 and see if it's still going to timeout after 20 minutes.

    -------------------------------------------------------------------------

    but theoretically you should never change it. Just forget that it's even
    possible :)


    George.


    <> wrote in message
    news:...
    > Thanks George for your solution.
    >
    > However I would like to know why it still times out when the timeout
    > value is stored in the web.config file. If anyone can shed some light
    > on this it'd be appreciated.
    >
    > Thanks
    > Stephen
    >
    George Ter-Saakov, Feb 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Do
    Replies:
    2
    Views:
    6,366
  2. =?Utf-8?B?bWc=?=

    RE: session timeout in Web.config & IIS

    =?Utf-8?B?bWc=?=, Jul 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    506
    =?Utf-8?B?bWc=?=
    Jul 4, 2004
  3. CSharpner
    Replies:
    0
    Views:
    1,021
    CSharpner
    Apr 9, 2007
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,275
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,281
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page