如何在相应网页上有活动时更新cookie的值 [英] how to update the value of the cookie when there is an activity on corresponding web page

查看:59
本文介绍了如何在相应网页上有活动时更新cookie的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们要求用户需要在15分钟不活动状态下退出应用程序。此时间作为参数从web.config文件发送到应用程序。



We have a requirement that the user needs to be logged out of the application in 15 mins of inactivity. This timing is sent as a parameter to the application from the web.config file.

<add key="TimeOutValue" value="900"/

>



该值在主登录页面中调用,如下所示

>

The value is called in the main login page as below

If vipSoapInterfaceResponse.statusMessage = "Success" Then
                   Response.Cookies("IMF")("UserID") = lblUserID.Text.ToString()
                   Response.Cookies("IMF")("UserName") = txtUsername.Text.ToString()
                   Response.Cookies("IMF").Expires = DateAdd("s", TimeOutValue, Now())





这是注销用户,无论他们在15分钟内做了什么活动。

如果每次用户处于活动状态时如何更新cookie,只有在真正不活动时才将其注销?



This is logging out the user irrespective of any activity they do in 15 mins.
How do I update the cookie every time the user is active and only log them out if there is real inactivity?

推荐答案

你的cookie更新代码需要在每个请求上运行,因此如果您有mvc布局或webforms母版页,则将代码放在该代码上。否则你需要找到一些其他方法在每个页面上运行它,比如global.asax文件中的事件等。
Your cookie update code needs to run on every request, so if you have an mvc layout, or webforms master page then put the code on that. Otherwise you'll need to find some other way to run it on every page, like the events in the global.asax file etc.


这篇关于如何在相应网页上有活动时更新cookie的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆