Apeksha
Apeksha

Reputation:

Delete all elements at application close in ASP.Net

Can anyone help me in this. Am using Asp.NET WITH C#. I am have an number of products in my database. When I run my code all the products values are stored in a database table. Without an exit button, if I close my application, when I run for second time the database table should be empty. I CANT USE !PAGE.ISPOSTBACK because I add different products at single run time, which will delete for single users. Could anyone tell me, or show code for deleting elements as the application is closed without internal exit button event.

Upvotes: 0

Views: 830

Answers (2)

Yoann. B
Yoann. B

Reputation: 11143

You should add some Cache Item and a Cache Expiration CallBack with SlidingExpiration.

So you can handle deleting all your items when Expiration CallBack is fired whenever the users didn't click on the Exit button.

Check this out : http://geekswithblogs.net/jawad/archive/2005/05/23/CacheManager.aspx

Upvotes: 0

Jason Jackson
Jason Jackson

Reputation: 17260

If you are using a web application, there is no real way to determine when a user leaves your app. There are a variety of strategies you can use, but none of them are 100% reliable. These strategies include:

  1. Session timeout of user causes log-off logic to execute (deleting rows).
  2. Using Javascript to detect when the user is navigating away from the page and firing an AJAX call to do log-off logic.
  3. Detect browser close with Javascript and call AJAX like #2.

You may wish to reverse the logic here. Why not run some logic when the user logs in to detect these orphaned rows, and delete them?

Upvotes: 1

Related Questions