ASP.NET - 存储临时文件 [英] ASP.NET - Store Temporary Files

查看:34
本文介绍了ASP.NET - 存储临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络表单,允许用户在我们的系统中打开工单时上传文件.上传是使用ajax 控件工具包"asyncFileUpload 控件完成的.

I have a web form that allows users to upload files while opening a ticket in our system. The upload is done using the "ajax control toolkit" asyncFileUpload control.

这个想法是将文件保存到临时目录,并且只有在用户点击提交"按钮时才将它们保存到永久位置.

The idea is to have files saved to a temp directory and only save them to the permanent location when the user hits the "commit" button.

我希望能够删除不再相关的临时文件(例如,用户将页面打开一个月而没有发布表单).

I would like to be able to get rid of temp files that are no longer relevant (e.g. the user leaves the page open for a month without posting the form).

不永久保留临时文件的最佳方法是什么.也许将他们的文件保存在会话中?也许将它们保持在视图状态?

What would be the best way to not keep temp files forever. Maybe keeping them files in the session? Maybe keeping them in the viewstate?

我可以向页面添加一些带有超时的 JS,并添加一些在用户离开页面时运行的代码.但这些想法是客户端解决方案.我不希望有人篡改代码并在我的系统上留下垃圾.

I could add some JS to the page with a timeout and add some code that runs when the user leaves the page. But these ideas are client side solutions. I wouldn't want someone to tamper with the code and leave me rubbish on my system.

还有其他想法吗?

谢谢,夏季灯泡

推荐答案

我的建议是在 Global.asax 中添加一个 On_SessionEnd 处理程序,并在用户会话结束时删除临时文件.您可以命名临时文件,将 SessionID 附加到它们(或预先添加 SessionID,无论您想要什么),这样您就只会删除会话已结束的用户的文件.您还可以向 Global.asax 添加 On_Application_End 处理程序以删除临时目录中的所有文件.

My suggestion is to add an On_SessionEnd handler in Global.asax and delete the temp files when the user session ends. You can name the temp files appending the SessionID to them (or prepending the SessionID, whatever you want) and that way you would only delete the files for the user whose session has ended. You could also add an On_Application_End handler to Global.asax to delete ALL files in the temp directory.

这篇关于ASP.NET - 存储临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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