简体   繁体   English

jQuery ajax调用表单身份验证问题

[英]jquery ajax calls form authentication issue

I am making jquery ajax calls to server after each 10 seconds from a page. 我每隔10秒就会从页面向服务器进行jquery ajax调用。 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. 现在,当用户向服务器发出正常请求(没有ajax调用)(如果他空闲2分钟)时,我希望该用户注销。 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. 我已经用超时2分钟制作了一个表单身份验证cookie,但是问题是自动jquery ajax调用(每10秒之后)不会使用户未经身份验证。 How can I handle this case. 我该如何处理这种情况。

Clear the interval and remove the authentication cookie after 2 minutes : 清除间隔并在2分钟后删除身份验证cookie:

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. 我猜想在服务器端有一个检查身份验证cookie的方法-如果找不到它,则用户被迫重新进行身份验证。

You can make a validation function @ server side . 您可以在服务器端设置验证功能。 every ajax request call this validation first and if valid execute your script normally . 每个ajax请求都首先调用此验证,如果有效,则正常执行脚本。 if not valid you can clear cookies . 如果无效,您可以清除cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM