加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何防止会话超时

发布时间:2020-12-15 08:09:00 所属栏目:百科 来源:网络整理
导读:我知道这对你们大多数人来说可能是一个简单的问题.但我的问题是我的服务器主机每分钟都清空会话池.那么如何让我的用户保持登录超过一分钟? 我听说我可以使用SessionStates,但是我没有在网上找到任何像我这样的新手很容易使用的指南. 我也听说过用饼干做这件
我知道这对你们大多数人来说可能是一个简单的问题.但我的问题是我的服务器主机每分钟都清空会话池.那么如何让我的用户保持登录超过一分钟?

我听说我可以使用SessionStates,但是我没有在网上找到任何像我这样的新手很容易使用的指南.

我也听说过用饼干做这件事.怎么样?

我正在使用C#和.Net

解决方法

这是一种方式:

http://weblogs.asp.net/stevewellens/archive/2009/06/09/ah-ah-ah-ah-staying-alive-staying-alive.aspx

Sometimes you want your web page to ‘stay alive’. That is,if a user is filling out a complicated form,you do not want the session to time out before they are finished. The user could get very angry and rightfully so: You might even get yelled at!

It’s not simply a matter of increasing the session timeout to a very large value. If you do that,the sessions would be left active in the server memory for hours—long after the visitors have left the site. Increasing the session timeout IS a solution… but not necessarily a good solution.

The goal is that the session should stay active as long as the web page is open on the client machine …even if there are no post backs to reset the session timer. When the web page is closed,the session should time out normally.

I implemented a solution for this: The client will “ping” the server at intervals of less than the session timeout which will reset the session timer. This is known as the Heartbeat design pattern (I couldn’t find a decent site/page to link to)…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读