Use Ajax to maintain sessions

Source: Internet
Author: User

In a project, you need to make the session variable exist in the whole cycle before the page is closed, and try to implement it using asp.net ajax. The Code is as follows:
On the. aspx page, <body> tag: <body onload = "KeepActive ();">
Client JS Code:
Function KeepActive (){
PageMethods. KeepSession ();
SetTimeout ("KeepActive ();", 600000 );
}
Background. cs code:
[System. Web. Services. WebMethod]
Public static void KeepSession ()
{
}

The purpose of the code is to allow the client to regularly call the server method so that the session status is not limited by the Session Timeout setting. From the actual running effect, most of the time can achieve the expected purpose. However, as we all know, sessions will be lost in some cases, so this method is powerless for Session loss due to non-timeout.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.