如何在ASP.Net项目启动时清理SQL表? [英] How do I clean up an SQL-Table on startup of ASP.Net project?

查看:93
本文介绍了如何在ASP.Net项目启动时清理SQL表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿.
所以我有以下情形:
每次用户登录时,我都会在一个表中写入一个字段,该字段显示是否有活动的会话.当用户断开连接时,它将设置该字段,以便说用户断开连接,并且会话无效.现在这是明显的问题.当我关闭网站时,这些字段将不会设置为无效,并且在下次启动该网站时,会出现一堆无效的会话.我可以手动将它们全部设置为无效,但这是一个相当草率的解决方案.我想知道是否可以使用某种机制在asp.net网站开始时将字段初始设置为无效?

提前谢谢.
Dennis

Hey there.
So I have the following scenario:
Everytime a user logs in I write into a table with a field that displays whether there is an active session or not. When the user disconnects, it sets the field so that it says that the user is disconnected an the session is invalid. Now here''s the obvious problem. When I shut the site down, the fields wont be set to invalid and on the next startup of the site, there are a bunch of invalid sessions. I could set them all to invalid manually but that''s a rather sloppy solution. I was wondering if there''s any mechanism I could use to set the fields initially to invalid on start of the asp.net site?

Thanks in advance.
Dennis

推荐答案

使用global.asax文件中的Aplication_start事件.您可以在此处编写自定义逻辑以清理无效的会话.这是每次应用程序启动时都会调用的第一个事件.
Use Aplication_start event from the global.asax file. You can write your custom logic here to cleanup the invalid sessions. This is the first event to called every time application starts.


这篇关于如何在ASP.Net项目启动时清理SQL表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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