0

I've created an ASP.NET web form site.

The site allows the user to write articles, and upload attachments as well.

While the user is writing the article, any uploaded attachments are moved into a temp folder that I created in my site folders, and just when the user submits the article, the attachments are moved to an appropriate path,

But what if the user closed the form, discarding the article? are files in the temp folder will be permanent? of course not!

SO

I want to determine a good scenario for deleting the temp files regularly, without deleting any files that are in pending.

I'm thinking about a scenario:

  • Deleting any files that are created for more than an hour! (using file system functions) and that occures in the Application_Start event or Session_end

Any better ideas?

1 Answers1

2

I would do it as a stand-alone Windows Service.

If you add that logic to an Application_Start event, if your site is constantly visited (and never recycled by IIS), you'll only run that process once. You'll also have the potential to dramatically slow the initial precompile of the site for the first visitor.

Session_end could be good, but if two people have it end at the same time, you could run into a race condition.

A Windows Service gives you the benefit of always running (and not using CPU when waiting, if written correctly), and it doesn't interfere with the working of your ASP.NET site.

Garrison Neely
  • 3,238
  • 3
  • 27
  • 39
  • but I think it's not easy (not legal in most cases) to add a Windows Service into the host's Windows? – Hashem AL-Rifai Jun 24 '13 at 22:56
  • You don't necessarily need to have the Service running on the same box as the Web Server (though it'd be easier). As long as the Windows Service runs under an account that has access to the Web Server's `temp folder` directory (the one you configured, not C:\Temp), it could run from any server that has physical access to that Web Server. – Garrison Neely Jun 24 '13 at 22:58
  • Aha, that's OK, Thanks @GarrisonNeely – Hashem AL-Rifai Jun 24 '13 at 23:01