How to handle temporary files in an ASP.NET application

I recently worked on displaying workflow diagram images in our web application. I managed to use the reconstructed WF constructor and create images on the fly on the server, but, imagining how large the workflow diagrams can become very quickly, I would like to give a better user experience using some ajax control to display images that support zoom functions and panning.

I happened to meet the seadragon site, which seems to be just awesome work that I could use. There is only one drawback - in order to use my library to generate images with deep image scaling, I have to use the file structure on the server. Due to the temporary nature of the images that I use (workflow diagrams with progress indicators), it is important not only to create such images, but also to get rid of them after a while.

Now the question is, how can I better make sure that temporary image files and a folder hierarchy can be created on the server (ASP.NET web application) and then cleaned up. I thought about using the cache functions and after the expiration of the cache element I deleted the corresponding hierarchy of image folders or just in Application_Start and Application_End from Global.asax I deleted the contents of the entire temporary folder, but I'm not quite sure if this is a good idea and if there are any security restrictions or file system related issues. What do you think?

+4
source share
3 answers

We do something similar to create reports in PDF format, and the easiest way is to use a timestamp check to determine how the "old" files are and then delete them based on a time period, in our case more than 2 hours. This is done before creating the next PDF, but as part of the creation process. We also created a specific folder and granted the user access to write / write ASP.Net to the folder.

The only drawback is that if the PDF creation process is not used regularly, a collection of files will be created, but they will eventually be cleaned up. After 2 years and 4000 pdf each, we have not made a mistake yet.

+2
source

Use the App_Data folder. This folder is located inside your application and is writable by your application without leaving the application context, but is also protected from accidental viewing. It is designed to store data files for your application.

Application_Start and Application_End will only start once, so if you need a cleaner cleanup, I would consider using a cache structure or a simple Windows service to handle cleanup.

+1
source

First, you need to make sure that your IIS workflow has permission to write / delete files from your cache directory (and not the rest of your site, just in case)

2nd, I would stay away from using App_Start and App_End, the end of the file cleaning application was not 100% guaranteed, and you could get a growing bunch of lost images.

I would do the planned process, perhaps once an hour, or once a day, depending on what you want. And check how old each image in your cache is, and if it is older than your arbitrary "expiration time", then delete it.

In addition, it is not so much.

0
source

All Articles