如何防止会话超时 [英] How to prevent session timeout
问题描述
我知道这对大多数人来说可能是一个容易的问题。但我的问题是,我的服务器主机每分钟清空他们的会话池。那么如何让我的用户保持登录超过一分钟?
I know this is probably an easy question for most of you guys. But my problem is that my server host empty their session pools every minute. So how do I get my users to stay logged in longer than one minute?
我听说我可以使用SessionStates,但我还没有找到任何指南
I've heard that I could use SessionStates, but I haven't found any guides on the net that's easy to use for a newbie like me.
我也听说过用饼干做的事情。如何?
Also I've heard about doing it with cookies. How?
我正在使用C#和.Net
I'm working with C# and .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.
我实现了一个解决方案:客户端将ping服务器的间隔小于会话超时,将重置会话计时器。这被称为心跳设计模式(我找不到一个不错的网站/页面链接)...
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)...
这篇关于如何防止会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!