设置无限会话超时 [英] Setting unlimited session timeout

查看:86
本文介绍了设置无限会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要让应用程序的会话保持活动状态。我已经看到它可以设置为某个时间



Sub Session_OnStart

Session.Timeout = 90

结束次级



有没有办法无限制?

谢谢

Hi,
I need to keep the session of my application alive. I have seen that it can be set to a certain time by

Sub Session_OnStart
Session.Timeout = 90
End Sub

Is there any way to make in unlimited?
Thanks

推荐答案

虽然理论上可以使任何进程内会话的超时无限,但实际上这不是一个好主意(当进程会话被回收时,工作进程被回收,所以在某些时候服务器可能会决定它需要停止并启动工作进程,从而删除会话)。



最好用一个例子来解释它不是一个好主意的原因。假设您是像亚马逊这样的高流量网站,让我们将您的网站称为尼罗河。现在,我访问您的站点并将一些项目添加到基于会话的购物车中,并且会话存储在SQL Server中,因为您真的很好并且您有一个Web场。现在,我关闭浏览器并返回到您的站点并决定添加更多项目。事情是,我现在正在进行新的会议。但是等等 - 旧会话仍在数据库中。现在有两套会议 - 只有一套是相关的,另一套是陈旧的。好吧,我无法决定我想要什么,所以我关闭浏览器并在当天晚些时候回来。我现在有三个会话 - 两个陈旧和一个活跃。对您而言,好消息是您的网站在网上提供了一些最优惠的价格,因此它非常受欢迎 - 您每小时吸引100万购物者。



可以你看到你的会话数据会如何迅速增长?



如果你有这个要求 - 你需要分析你的问题是什么真的想要克服。我保证它不是您认为的那个。
While it's theoretically possible to make the timeout for none in-process session infinite, in practice it is not a good idea (in-process session is recycled when the worker process is recycled so at some point the server may decide that it needs to stop and start the worker process, thus removing the session).

The reason that it's not a great idea can best be explained by an example. Suppose that you are a high traffic site like Amazon, let's call your site Nile. Now, I visit your site and add some items to a session based shopping cart and the session is stored in SQL Server because you're being really good and you have a web farm in place. Now, I close the browser down and come back to your site and decide to add some more items. Thing is, I'm now in a new session. But wait - the old session is still in the database. There are now two sets of sessions for me - only one of which is relevant, the other one is stale. Okay, I can't decide what I want so I close the browser down and come back later on in the day. I now have three sessions - two stale and one active. The good news for you is that your site offers some of the best prices on the web so it's hugely popular - you're attracting 1 million shoppers every hour.

Can you see how staggeringly big your session data is going to grow very quickly?

If you have a requirement for this - you need to analyse what the problem is that you're really trying to overcome. I'll guarantee that it's not the one you think it is.


通过Http Handler让您的站点与主站点进行通信。我通常会使用这样的简单设置:
Keeping your site communicating back with a main site via an Http Handler. I would typically use a simple setup like this:
function heartbeat(timeout) {
  setTimeout("triggerHeartbeat", timeout);
}

function triggerHeartbeat() {


.get( / Heartbeat.ashx
null
function (data){
heartbeat( 600000 ); // 每10分钟触发一次......
}, json);
}
.get("/Heartbeat.ashx", null, function(data) { heartbeat(600000); // Triggers every 10 minutes... },"json"); }

现在你的心跳会每10分钟发出一次(Ajax查询中的调用只会将下一次triggerHeartbeat调用设置为10分钟后发生。你可以用<$替换它c $ c> setTimeout(triggerHearbeat,600000); 如果你想摆脱心跳方法(不要忘记你必须触发第一次通话)。



无论如何,这是客户端所需的所有代码 - 除了在

Now you have a heartbeat that will pulse every 10 minutes (the call in the Ajax query simply sets up the next triggerHeartbeat call to happen 10 minutes later. You could replace this with setTimeout("triggerHearbeat", 600000); if you wanted to get rid of the heartbeat method (don't forget you'll have to trigger the first call).

Anyway, that's all the code you need on the client side - other than putting the initial call to heartbeat in a

这篇关于设置无限会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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