如果会话过期,如何从代码后面的表中删除表? [英] How to drop table from code behind file if session expire?

查看:57
本文介绍了如果会话过期,如何从代码后面的表中删除表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实际数据库中创建表,基于button1点击事件中用户的sessionid并在其中添加记录,在button2点击事件中,我做了一些处理,最后删除了该表。它工作正常。



但是如果用户没有点击button2或移动到另一个页面或会话过期或用户关闭浏览器,在上面的secanario我的表存在就像在数据库中一样。我怎么能删除它table?



我无法创建临时表。如果我的sql连接关闭临时表自动被删除。这是我从网格中获取有分页的记录。如果用户从第一页中选择一些记录并单击button1,创建表并将记录添加到该表中,当用户移动到第二页并选择记录时,该记录将添加到表中。

I am creating table in actual database,base on sessionid of user in button1 click event and adding record into it and in button2 click event, I doing some processing and finally droping that table.It is working fine.

But if user does not click on button2 or move to another page or session expire or user close browser,in above secanario my table exist as it as in database.How can I drop that table?

I can't create temp table.If my sql connection closes temp table automatically get dropped.Here I am fetching record from grid that have paging.If user select some record from page one and click on button1,table get created and record get added into that table,when user move to second page and select record,that record get added into table.

推荐答案

使用global.asax文件中的Session End事件来删除数据(如果您需要使用session_end的示例代码,请使用google),但它不可靠,并不总是开火。如果您使用SQL或State Server等进程外会话存储,它也永远不会触发。



唯一可靠的方法来清理数据是运行一个只删除表中旧记录的SQL作业。当您创建行存储创建时间并且每天或每隔几小时运行一个sql作业时,它会删除比给定日期更早的记录。
Use the Session End event in the global.asax file to remove the data (google if you need sample code for using session_end), however it's unreliable and doesn't always fire. It'll also never fire if you're using out-of-process session storage like SQL or State Server.

The only reliable way you can clean up your data is to run a sql job that simply deletes old records from your table. When you create the row store a creation time also and have a sql job that runs every day, or every few hours, that deletes records that are older than a given date.


这篇关于如果会话过期,如何从代码后面的表中删除表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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