Reputation: 23
I would like to create temporary tables during a session. When the session ends (user ends the browser connection) I would like the drop the temporary tables. So I need be able to call a function that reads the table names saved in say Session["temp_tables"]
and query the database to drop them.
Upvotes: 0
Views: 155
Reputation: 3236
Sessions can end for a variety of reasons that aren't necessarily associated to a user finishing use of your website (i.e. timeout, machine restart, etc). Generally speaking, I usually avoid using ASP.NET session state.
A couple of alternatives might be:
Have the user tell you when they're done with the data (saved "sessions"). This has the benefit of being simple to implement & allow the user to leave\return at a later time and continue where they left off.
Have a "last used" value in the tables & set up a scheduled task to cleanup stale data.
Upvotes: 1
Reputation: 2157
Use the session end event in your global.asax file.
void Session_End(Object sender, EventArgs E) {
//remove temporary table
}
This will run after the users session times out, and not necessarily when they close their browser window.
Upvotes: 0