Search code examples
c#asp.nettemporary-files

Creating public temporary files with expiration time


I'm building a small webapp on win2003 with asp.net 2.0. I need to create small files that i suppose to be accessable by for the web and the files is suppose to have 10 minute expiration time. I didn't find any support for this in the framework and my other solution that came to mind was to have a schedule job that cleans the file ever X minute. But somehow I think I'm not the first one to experience this problem and wondering if there are any other smart solutions.

Thanks in advance.


Solution

  • Without knowing more about why you are doing this, I think your solution of an external program to clean the files out is the best solution. An alternative might be to store the "files" in a database and create a handler that retrieves the data from the database, but only if the "file" is not expired. You could then schedule a clean up task on the database much less frequently and still only serve up the "files" that are not expired. Creating them on disk would force you to do the clean up on a regular schedule to ensure that expired items are no longer available.

    I suppose you could also do the handler with on-disk files and check the creation date before serving the file up. In this case the folder containing the actual files would need to be outside the web site or in a restricted area that prohibits direct access from normal users.