Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 How to avoid Session Timeouts in an Asp.Net Page?
Posted by Moderator1 on  5/14/2010 7:42:17 PM 8931 Views
Regardless of the session timeout that is set in the IIS or in the web.congif file, we can increase the time limit of the sessions in one particular or many Asp.Net pages. Place the below JavaScript code in your Asp.Net page that need more time than the Session Timeout time,

<script language="javascript" type="text/javascript">
function fnKeepSessionAlive()
var myurl = "Activate_Session.aspx";

if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest()
else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP")
}"POST", myurl, true);

window.setTimeout("fnKeepSessionAlive();", 60000);


The above JavaScript function called "fnKeepSessionAlive()" uses the XMLHttpRequest to call another Asp.Net page as an asynchronous request. So the request to the page is internal and there won’t be any postback actions visible in the client browser. This JavaScript function is called recursively for every minute. You can adjust the time to 5, 10 or any number of minutes as per your requirement.

1. The time to call the function fnKeepSessionAlive() should not exceed the Session Timeout time.
2. Make sure "Activate_Session.aspx" is physically present in your application folder. This must be an aspx page with or without codes.

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter
A free sample chapter from Packt Enterprise's book: Microsoft Silverlight 4 and SharePoint 2010 Integration.
Simply JavaScript - Free 150 Page Preview!
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
100% Free Subscription until Stock lost.View complete list.
Sponsored by