I guess every ASP.net developer might be using Updatepanel control these days which lets us to do partial postbacks on the page .If you are using Updatepanel control once on your page , you wont come across any issues . But if you are using it extensively obviously you will run into many issues.
In a traditional ASP.net web application the users session timeout counter will be reset everytime a user requests a page from the server, thus by preventing the user’s session from getting timed out. However,In AJAX ASP.NET application which uses XMLHTTP request to update part of a page , the users session counter on IIS will not be reset . So How to prevent Timeout in AJAX Asp.net Application which uses updatepanels ? How can we reset user Session in IIS when so activity happens in updatepanel ? The solution is here . Read on .
In a traditional ASP.net web application the users session timeout counter will be reset everytime a user requests a page from the server, thus by preventing the user’s session from getting timed out. However,In AJAX ASP.NET application which uses XMLHTTP request to update part of a page , the users session counter on IIS will not be reset . So How to prevent Timeout in AJAX Asp.net Application which uses updatepanels ? How can we reset user Session in IIS when so activity happens in updatepanel ? The solution is here . Read on .
- Create a new WebForm - KeepAlive.aspx in your application.
- Now go to the code behind of the webform by hitting F7.
- In the page_load method of the webform (KeepAlive.aspx) add the following lines of code
Response.ContentType = "text/html";
Response.Write("Technade");
- Now go to the page where you are using the updatepanel extensively and add the following javascript to the markup.
function sessionKeepAlive(sender, args) {
//Create a New web Request and make a call to KeepAlive
var SubRequest = new Sys.Net.WebRequest();
SubRequest.set_url("KeepAlive.aspx");
SubRequest.set_httpVerb("POST");
SubRequest.add_completed(sessionKeepAlive_Callback);
SubRequest.set_body();
SubRequest.get_headers()["Content-Length"] = 0;
SubRequest.invoke();
}
//This function processes the return values
function sessionKeepAlive_Callback(executor, eventArgs)
{
// If you want to check any returned value from server ,you can use this else skip it
//else leave as it is
}
//Raised after an asynchronous postback is finished and control has been returned to the
// browser.
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(sessionKeepAlive)
- What we are doing above is that, whenever you make a asynchronous postback call to the server , we are requesting the KeepAlive.aspx from the server using a new web request which inturn will reset the user session in IIS.
This solution has been tested and it works. So you dont need to worry that your updatepanel activity is not resetting the session in IIS.I hope this one helps the developers.Please post your doubts and views as comments.This one also might help you
For more ASP.NET solutions , Subscribe here or click here to get updates via email .
How to remove 'sys' is undefuned ?
For more ASP.NET solutions , Subscribe here or click here to get updates via email .