IIS 6+ASP.NET - many temp files generated

user123093 picture user123093 · Mar 25, 2010 · Viewed 8.3k times · Source

I have a ASP.NET + some .NET web-services running on IIS 6 (win 2003 server). The issue is that IIS is generating a lot (!) of files in "c:\WINDOWS\Temp" directory. a lot of files means thousands of files, which get to more than 3G of size so far.

The files are generated by this command: C:\WINDOWS\SysWOW64\inetsrv> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\vfagt\113819dd\db0d5802\assembly\dl3\fedc6ef1\006e24d8_3bc9ca01\VfAgentWService.DLL" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /out:"C:\WINDOWS\TEMP\9i_i2bmg.dll" /debug- /optimize+ /nostdlib /D:_DYNAMIC_XMLSERIALIZER_COMPILATION "C:\WINDOWS\TEMP\9i_i2bmg.0.cs"

The files in the temp directory are pairs of *.out & *.err, where the *.err file is zero size, and the *.out file contains the compilation output messages.

What is causing IIS to generate so many files?

How can I prevent it?

UPDATE:

The problem is that the command i described above (csc.exe) is being executed many (many) times, causing the .out & .err to be generated so many times, until it consumes the disk space.

So - my question is: what is causing this command to run so many times? (i don't have that many .aspx & .asmx files in my web app).

Thanks, Moe

Answer

Cheeso picture Cheeso · Mar 25, 2010

You can't prevent it. IIS + ASP.NET dynamically compile files like .aspx, .asmx, .ascx, .ashx, .asax, and others. These are all template files, that eventually get transformed into source code in the chosen language - C#, VB.NET, or whatever you choose to write your ASPX pages in.

The model for ASP.NET, when a request for a page is received, is this:

  • check to see if an assembly for the requested page is available and up to date. if it is, pass the request to the page.
  • if not, produce source code from the templates involved (aspx, ascx, etc). Put the generated source code into the ASP.NET Temp directory.
  • compile the source files into assemblies that are dynamically named and also placed in the temporary directory. If you use C#, that means it runs csc.exe, as you have seen.
  • load the newly compiled assembly.
  • pass the request to that assembly (eg, step 1)

The .out and .err files are just the stdout and stderr from the invocation of csc.exe. Those are not likely to consume 3gb of filesystem space.

But, ASPNET also keeps temp copies of all assemblies referenced by any of the pages or controls (etc), in that directory tree. If you reference System.Xml.dll in three distinct ASPX pages, then there is a copy of System.Xml.dll places into three distinct temp directories in the ASPNET temporary files dir tree. These copies can accumulate and it wouldn't surprise me to hear that most of your 3gb is in copies of DLLs.

Read more about this at http://www.codeproject.com/KB/aspnet/ASPXFILES.aspx

You can delete any files in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files directory. This won't be possible while IIS and ASP.NET are active. If you have a maintenance period, you can delete them when the site is down. If it's a dev machine, just stop IIS (net stop w3svc) delete all subdirectories in that folder, then restart IIS (net start w3svc).


Related:
- Eliminating temporary ASP.Net Files
- What is the “Temporary ASP.NET Files” folder for?