开发者

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

开发者 https://www.devze.com 2022-12-27 22:29 出处:网络
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

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开发者_C百科 quit the page with no action or cancel button.


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号