Rocky Singh
Rocky Singh

Reputation: 15430

jquery ajax calls form authentication issue

I am making jquery ajax calls to server after each 10 seconds from a page. Now when a user makes normal request (no ajax call) to server (if he stays idle for 2 minutes) I want the user to become log out. I have already made a form authentication cookie with timeout 2 minutes but the issue is that automatic jquery ajax calls(after each 10 seconds) are not making the user unauthenticated. How can I handle this case.

Upvotes: 0

Views: 607

Answers (2)

Manse
Manse

Reputation: 38147

Clear the interval and remove the authentication cookie after 2 minutes :

var intervalID=window.setInterval(yourajaxfunction,10000);

window.setTimeout(  
    function() {  
        clearInterval(intervalID);   // cancel the ajax requests
        clearCookie(); // remove the authentication cookie locally
    },  
    120000  // 2 minutes timeout
);

I'm guessing that on the server side there is a check for the authentication cookie - if its not found then the user is forced to re-authenticate.

Upvotes: 1

Sameh Serag
Sameh Serag

Reputation: 746

You can make a validation function @ server side . every ajax request call this validation first and if valid execute your script normally . if not valid you can clear cookies .

Upvotes: 0

Related Questions