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

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

问题描述

我有一个Web表单,允许用户上传文件,而在我们的系统中开了罚单。
上传使用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.

任何其他想法?

谢谢,
Summerbulb

Thanks, Summerbulb

推荐答案

我的建议是在Global.asax中添加On_SessionEnd处理程序,并删除当用户会话结束临时文件。您可以命名临时文件追加的SessionID他们(或在前面加上的SessionID,任何你想要的),而且这样你只会删除文件的会话结束用户。您还可以添加一个On_Application_End处理程序的Global.asax在临时目录中删除所有文件。

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天全站免登陆