By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,119 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,119 IT Pros & Developers. It's quick & easy.

Web.config session timeout

P: n/a
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 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.No Cache);

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/...arentpixal.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.

<st******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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 '06 #2

P: n/a
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 '06 #3

P: n/a
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.
<st******@hotmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.