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.
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.
If this happens on production then add this to you web.config.
(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.