One one of my project i was told that the user will keep the browser open and will
talk to their client for long time, which may be 1/2 hour continuous and after that
they will come back and add some item to the page as per the discussion over the
phone. So we have to keep the session live till that period to keep him logged in.
The way to implement this are
1) Add the following code in web.config file
<sessionState timeout="100"></sessionState>Here timeout is in munites and sessionwill stay live upto 180 min i.e 3 hours
(by default the timeout is 20 mins) which was enough for our purpose.
But with this way of implementation we were misusing the valuable server disk space
for all the session variables will stay for that long time. So even if you close
the browser the objects will stay in the server for next 3 Hours. So we implemented
2) In the Body tag of our aspx page i put a div which is having display style attribute='None'
so that the div does not display in the page.
And then put a IFrame inside the div and set another aspx page (KeepSession.aspx)
as the src of the IFrame. The the page in the IFrame i make it auto refresh after
18 mins. In this way though the session is to be expired in 20 mins (by default),
but the KeepSession.aspx page will be reloaded in every 18 mins and the session
will be refreshed and it will start counting the 20 mins expire time from start.
So in this way it will stay alive for ever. Below in the quote in my NewQuote.aspx
<iframe id="redresh" src="RefreshSession.aspx" height="0" width="0">
<form id="form1" runat="server">
<div>YOUR PAGE CODE HERE </div>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="KeepSession.aspx.cs"
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="refresh" content="1048" />
<!--Here the content value is the no of secconds
after which the page will be reloaded automatically. Make it less than the session
expire time -->
<form id="form1" runat="server