Dyppl
Dyppl

Reputation: 12381

ASP.NET: Writing web-accessible temp files without application restart

My ASP.Net application used to restart unpredictably during requests, ruining my state, session data etc. I determined that the problem was caused by a control that writes and deletes some files in Temp folder that it creates near bin folder, so the web directory looks like this:

bin
Temp
....
Default.aspx    
web.config

ASP.Net apparently reacts to changes inside Temp folder the same way it reacts to changes inside bin or in web.config - it restarts the application.

I could partially solve the problem by moving the Temp outside the site directory. That way the application doesn't get restarted every time something temporary is written\deleted, so this part works well. The problem is that some of the files inside Temp directory should be web-accessible - like images generated on the fly and such.


So my question is actually threefold:

  1. Should ASP.Net application get restarted even if the changes are made not in the bin directory, but in another directory at the same level? Or is there something wrong with my configuration?
  2. Where and how do I create a temporary folder so it's web-accessible but it doesn't cause application restart?
  3. How do I turn off restart on directory change from code or web.config (both in IIS and ASP.Net development server)?

Upvotes: 3

Views: 1019

Answers (1)

Baz1nga
Baz1nga

Reputation: 15579

Based on my understanding here is the answer to your questions:

  1. ASP.NET restarts the application when too many files are changed in one of the content directories. For more info abt when app restart happens read: http://programming360.blogspot.in/2009/04/what-causes-application-restart.html
  2. You can create the temporary folder anywhere in the same machine or on a different machine(file-share) so long as the IIS-User has access to the folder it should work normally. The only thing that you need to consider is the latency when the folder is on a different computer.
  3. I dont believe you can control application restart and this is completely controlled by IIS. Might want to read up on this SO questions: ASP.NET restarts when a folder is created, renamed or deleted

Upvotes: 1

Related Questions