简体   繁体   English

恢复会话的最佳方法?

[英]Best way of reviving a session?

I'm having issues with my web-application expiring the session too soon (not unexpected, just too soon for the type of system I am developing). 我的Web应用程序的会话过期太早了(这不是意外的,对于我正在开发的系统类型来说太早了)。 My host doesn't allow changing the session expiration time. 我的主持人不允许更改会话到期时间。

So I was thinking, is there any way that I can (in ASP .NET MVC) for instance save my session variables in a form, so that when that form is somehow submitted or the page has changed, I can reset the session variables? 所以我在想,是否可以(例如在ASP .NET MVC中)将会话变量保存为表单,以便以某种方式提交该表单或页面已更改时,我可以重置会话变量?

But with the above theory (if it's even a good theory), then how do I handle such stuff in my controllers? 但是,如果采用上述理论(即使是一个很好的理论),那么我该如何在控制器中处理这些东西呢? Or is there a better way to reach a session that is theoretically infinite? 还是有更好的方法来参加理论上无限的会议?

What you are describing is the standard use-case for cookies. 您所描述的是cookie的标准用例。 If your variables don't need to be secure, then save each in a cookie (or, if you want to do it right, have a "session object" that you serialize in a cookie). 如果您的变量不需要安全,则将每个变量保存在cookie中(或者,如果您想做对,请在cookie中序列化一个“会话对象”)。

If your variables need to be secure, save them in a database or flat file and save the encrypted row id in the cookie. 如果您的变量需要安全,请将其保存在数据库或平面文件中,并将加密的行ID保存在Cookie中。

You cannot retrieve a session. 您无法检索会话。 Once gone, it is gone (and that's good for security reasons). 一旦消失,它就消失了(出于安全原因,这很好)。

However, you can keep the session from expiring: 但是,您可以防止会话过期:

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

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

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