Hi all we Know that we had an option to set a session time out value. when the session time value expires we had a problem to again reallocating the session values and session time out with a long process.

 For some we need to keep alive the session values. To solve this problem we actually increase the session timeout value. but this is not a correct process.



Some time we may need to have more session timeout for some pages and less session time out value for some pages. At that time we will face the real problem. But we can over ride it very easily.

How to Increase the session time out dynamically ????

Yes this is the question we all have., From now onwards you can forget it.

Here i am including a automatic refresh page in the my actual page that need to be live always. Here i done it with meta refresh tag in one page and an IFRAME in my page. The IFRAME will run itself and change the query string parameter to avoid browser caching on the page.

Take a new page called autorefresh.aspx. Just copy the below code in that page.

In autorefresh.aspx :-
 <head runat="server">
    <title></title>
    <meta id="MetaRefresh" http-equiv="refresh" content="60000;url=Default2.aspx" runat="server" />
   
<script language="javascript">
   window.status = "<%=WindowStatusText%>";
</script>

In autorefresh.aspx.cs:-
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
        {           
            MetaRefresh.Attributes["content"] = Convert.ToString((Session.Timeout * 120) - 120) + ";url=KeepSessionAlive.aspx?q=" + DateTime.Now.Ticks;

            WindowStatusText = "Last refresh " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
        }
}
Now open you page in copy and paste this code, lets call it as yourpage.aspx

In yourpage.aspx:-
<IFRAME ID="Default1" src="autorefresh.aspx" frameBorder="0" runat="server" ></IFRAME>
Open web.config file

In web.config file you will find a tag named as <sessionState />., If yes overwrite this code with the below code other wise just copy and paste in between the tags <system.web> ...........</system.web>
<sessionState mode="InProc" timeout="540"/>
Now see build it and debug it., Now you will find the difference. I hope you'll enjoy it.
See you again. Feel free to leave your foot prints or make me a mail.

Share it

1 comments:

Post a Comment