3

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)?
Dyppl
  • 12,161
  • 9
  • 47
  • 68
  • The App_Data folder is a good place for this. – Tuan Jun 22 '12 at 07:35
  • @Tuan: do the rules from the Baz1nga's answer apply to it? It's under Web application folder, so how the server will react to writes\renames inside it? – Dyppl Jun 22 '12 at 07:38
  • 1
    nope, it's immune from that (see http://petesbloggerama.blogspot.com/2008/02/aspnet-writing-files-vs-application.html). Otherwise, it could not be used to store SQL Express data files. – Tuan Jun 22 '12 at 07:45
  • 1
    I did a bit more research, and according to this site: http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx, creating and removing folders, even in App_Data can cause a restart. Creating and removing just files, though, is fine. – Tuan Jun 22 '12 at 07:49
  • @Tuan Yes I make a delete files on the image directory and never notice a restart issue. – Aristos Jun 22 '12 at 08:03

1 Answers1

1

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
Community
  • 1
  • 1
Baz1nga
  • 15,485
  • 3
  • 35
  • 61
  • How would "folder anywhere in the same machine or on a different machine(file-share)" be accessible for browsers? That's one of the requirements: files in the temp folder must be available for download. What would an URL to that look like? – Dyppl Jun 25 '12 at 04:46