views:

848

answers:

5

Literally every second time I run a big ugly web site project, I get an UnauthorizedAccessException, with a message pointing to a DLL, e.g. Temporary ASP.NET Files\ctheweb\0d76d363\4695c81f\App_Web_vi6bbbpy.dll' is denied. I then stop and restart the project, and it runs fine. I do some testing, debugging, fixing, run it again, and get the error again.

I'm inclined to add a pre-build command to just clear that directory, but I always prefer to solve a problem with something other than a hammer, at least initially.

A: 

Make sure you don't have a process like "Windows Desktop Search" indexing that folder.

David
A: 

It sounds like you have something that's holding an open handle to that file; you can track it down using Filemon or some similar tool to see what process it is that's holding the open handle.

McWafflestix
+3  A: 

This happens a lot during development when you are constantly modifying the aspx pages, ASP.NET is trying to compile and VS is trying to compile and ASP.NET is trying to execute the files. Also, sometime the lock goes away when you reset IIS.

iisreset /stop
del "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\*.*"  /Q /F /S
del “C:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*” /Q /F /S
iisreset /start

If this happens on production then add this to you web.config.

<compilation tempDirectory = “C:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\Other\” />

(scroll to the side, the key is to pick some \Other\ folder than the default.

And finally, use a Deployment project to try to pre-compile everything in advance. No compilation means no attempt to replace things in the temp folder

Or you can try OS diagnostics and try to find out what process has a lock on that file and kill that process. Not worth the effort when easier solutions exist.

MatthewMartin
Please can someone explain why this post is voted down? Simply down-voting without contributing is not constructive and simply rude.
ProfK
I'm not about to defend random down voting, but your question said you didn't want to user a hammer and this is a sledge hammer I gave you. Because this is a development box and the script runs fast (unlike the worst hammer of all, a reboot), it seemed appropriate to me.
MatthewMartin
This is a good solution. However, put the iisreset before the two del commands as you want be able to do the delete because of the w3p.exe holding onto those files.
Marc
If using the VS built in server (Cassini), this is quite a sledgehammer approach to replacing the 'issreset' call, in PowerShell: get-process webdev.webserver*|killI use the wildcard because in my work it's sometimes webdev.webserver20 and sometimes webdev.webserver40.
ProfK
+1  A: 

I've had similar problems in the past due to the workstation's anti-virus program accessing the file at the "wrong" time. Another tool you can use to determine what has a file open: Process Explorer (recommended for your personal arsenal even if it doesn't prove useful here, frankly).

lance
+2  A: 

IF it is a lock caused by some external process like a virus scanner or a search indexer, then you might try using Windows permissions to lock down the rights of other users and processes to read the files. By default, the Temporary ASP.NET Files directory is available to Users, Administrators, IIS_USR, SYSTEM, and TrustedInstaller -- which is to say, just about everyone.

Try out MatthewMartin's advice of the different compilation folder;

<compilation tempDirectory = “C:\LimitedPermissionCompilationDir\” />

And then limit the LimitedPermissionCompilationDir folder to just the users and groups who need permission -- say, IIS_USR if you're running on IIS, or your own account if you are compiling for the file-based webserver.

Anyway, this is a relatively safe way to try things out, as you don't need to worry about affecting anything other than the site you're running.

Steve Cooper