C# On Quit WebPage Delete Files and Folders on Server with no user action

梦想与她 提交于 2019-12-12 01:29:58

问题


I have some problems to delete temporary folder and files on my server when users not finish some action in webpages and quit to other webpages. Initialy at Page Load folders are created to allow the user to load files.I have tried implementing destruction during Idisposable without success. Could someone point the best method to delete folders and files when user quit the page with no action or cancel button.


回答1:


You can investigate the OnUnload event of the page but, honestly, your best bet is to have a script run periodically and delete all files from the temp folder older than some reasonable amount. e.g. run at midnight and delete all files created more the 24 hours ago (or less, if disk space is a problem).




回答2:


I am not sure why you want to create temp folders and files. But deleting them on no action is ugly way to rely on, because you have depend on some timers. You could use System.IO.Path.GetTempPath() to get a temp file and system would take care of deletion.



来源:https://stackoverflow.com/questions/2709958/c-sharp-on-quit-webpage-delete-files-and-folders-on-server-with-no-user-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!