Clearing out "temporary asp.net files"
[Important note, 9 March 2012. I wrote the following blog post some time ago with mainly IIS6 and Windows Server 2003 in mind and as I state – for non-production scenarios. For later versions of IIS the folder permissions I reassert using XCACLS are incomplete. Specifically they do not include BUILTINIIS_IUSRS. I also do not discuss the fact that on 64-bit operating systems there will be a Framework64 folder as well as a Framework folder. The suggestion by Christopher Lewis in the blog comments is a good one.]
When I am testing out issues with ASP.NET dynamic compilation and shadow copying, I frequently need to ensure the contents of the "temporary asp.net files" folder have been removed so that I get a clean and consistent repro each time.
Normally I just do an IISRESET /STOP, delete the files manually and then do an IISRESET /START.
But I got bored of that so thought I would try to automate it with a command file.
First thought was to do a DEL /S "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files*.*"
This worked, but left the directory structure in place.
So my next thought was to do an RMDIR /S /Q "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files" and then just recreate the directory.
That certainly left me with an empty directory, BUT, the "NETWORK SERVICE" account under which my application pools usually run had no permissions to the newly created folder, so I got an "access denied" error as soon as I tried to browse an ASP.NET page.
Then I thougt I'd get clever and use the built in command line tool CACLS.EXE to give full control permissions to the built in IIS_WPG local group of which NETWORK SERVICE is a paid up member. (Any account you use as the identity for an application pool should be added to IIS_WPG rather than trying to give the account all the needed permissions directly. It's much simpler and more maintainable.)
What I didn't like about that was that CACLS.EXE does not appear to support a way of suppressing the "are you sure (Y/N)?" prompts.
So finally I grabbed a copy of XCACLS.VBS and got the following command file working:
iisreset /stop
rmdir /q /s "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files"
rmdir /q /s "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files"
md "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files"
md "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files"
xcacls "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files" /E /G MYMACHINEIIS_WPG:F /Q
xcacls "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files" /E /G MYMACHINEIIS_WPG:F /Q
iisreset /start
HTH
Doug
Comments
Anonymous
August 10, 2008
PingBack from http://www.easycoded.com/clearing-out-temporary-aspnet-filesAnonymous
August 11, 2008
Hmm... for /d %i in ("%systemroot%Microsoft.NetFrameworkv2.0.50727Temporary ASP.NET Files*") do RD /q/s %i (use %%i in batch files) would be much safer...Anonymous
August 11, 2008
Hi Christopher A point I should have made is that this is a method I put together that works for me and I am using it on test machines rather than production servers. Be interesting to know which of the two methods would be most performant especially in the case of large amounts of cached files. Also, I'm curious to understand what might be "unsafe" about the method I suggested? Thanks! DougAnonymous
August 14, 2008
Ask the Directory Services Team : MCS Talks Infrastructure Architecture joeware - never stop exploring…Anonymous
August 15, 2008
Another simple way to do this is using robocopy. Just create an empty folder in some place and them run robocopy with /MIR. For example: md %TEMP%empty robocopy %TEMP%empty "%systemroot%Microsoft.NetFrameworkv2.0.50727Temporary ASP.NET Files" /MIR rd %TEMP%empty about safety, i've no idea, but it has less code, and it's very possible that is faster for a large number of files ;-)Anonymous
January 12, 2009
This article is all about the C:WINDOWSMicrosoft.NETFramework64v2.0.50727Temporary ASP.NET FilesAnonymous
August 18, 2009
This requires IISRESET -Stop. We cannot do this on production website. Is there a way to clear Temporary ASP.NET Files folder without having to reset iis?Anonymous
August 18, 2009
cvsayani - Some files within "temporary asp.net files" relating to a live site will be locked and not deletable while the site is running. That is the only reason I suggested doing the IISRESET -Stop, as that is the only way to be sure that none are in use. You might be able to get more fine grained control of the temporary files by using the tempDirectory attribute of the <compilation> section in the config file: http://msdn.microsoft.com/en-us/library/s10awwz0.aspx. You could change the location used for the temporary files of the "live" site and then trigger an appDomain restart (in fact editing the web.config file would do this anyway). This ought to "release" all files that were used in the old temporary files location allowing you to delete them. Arguably however, an appDomain restart might be as impactful as an IISRESET (but quicker than an IISRESET /stop followed by clearing out all temporary files).Anonymous
June 22, 2011
If the files are locked at your production site it means they are assigned to an active application. You should not WANT to delete them. If your clearing up files from previous applications, sort by date modified, older folders will not be locked.Anonymous
May 22, 2012
Just make a small change in web.config file e.g give a space and save and application will restart on its own and clear all the temporary asp.net files. Its an easy way to clear asp.net temporary folder. If i am wrong kindly guide.Anonymous
May 24, 2012
Thanks prem. I was not aware that "tickling" the config file like that would clear down the "temporary asp.net files" content. Did you experience that happening yourself? DougAnonymous
September 27, 2012
The comment has been removedAnonymous
June 26, 2013
RE: Christopher G. Lewis Mon, Aug 11 2008 12:17 PM # Your example worked after putting quotes around %i as shown below example for .NET 4 Open Command Prompt as Administrator FOR /D %i in ("%SystemRoot%Microsoft.NetFrameworkv4.0.30319Temporary ASP.NET Files*") do RD /q/s "%i" Thanks.Anonymous
June 26, 2013
Thank you Mike!Anonymous
April 28, 2014
The comment has been removedAnonymous
April 28, 2014
The comment has been removed