Frequent Access Denied to Temporary ASP.NET Files
Asked Answered
O

7

18

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.

Oar answered 27/5, 2009 at 19:1 Comment(1)
I've been getting this error this week as well. However, it only started after I switched my app pool to 32-bit on a 64-bit machine. Is this your case too?Delcine
D
14

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.

Debbidebbie answered 27/5, 2009 at 19:15 Comment(5)
Please can someone explain why this post is voted down? Simply down-voting without contributing is not constructive and simply rude.Oar
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.Debbidebbie
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.Eventempered
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*|kill I use the wildcard because in my work it's sometimes webdev.webserver20 and sometimes webdev.webserver40.Oar
When this didn't work in our situation, we found out (using filemon and processmon) that the C# compiler writes intermediate files in the Windows TEMP (c:\windows\temp) before it places the result (pdb and dll) in the ASP.NET Temporary files. The Application Pool user did not have write-access to that directory.Diminutive
H
14

In my case the answer was trivial - it was never an error to begin with. For me, ASP.NET actually throws this internally every time it starts my web application, and I simply forgot the "break on all exception" setting on by accident (from another debugging session). I checked it off and everything worked fine.

For reference, here's the stacktrace:

>   mscorlib.dll!System.IO.__Error.WinIOError(int errorCode, string maybeFullPath)  Unknown
    mscorlib.dll!System.IO.FileStream.Init(string path, System.IO.FileMode mode, System.IO.FileAccess access, int rights, bool useRights, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy, bool useLongPath, bool checkHost)    Unknown
    mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, string msgPath, bool bFromProxy)  Unknown
    mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode)  Unknown
    System.Web.dll!System.Web.UI.Util.HasWriteAccessToDirectory(string dir) Unknown
    System.Web.dll!System.Web.HttpRuntime.SetUpCodegenDirectory(System.Web.Configuration.CompilationSection compilationSection) Unknown
    System.Web.dll!System.Web.HttpRuntime.HostingInit(System.Web.Hosting.HostingEnvironmentFlags hostingFlags, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException) Unknown
    System.Web.dll!System.Web.HttpRuntime.InitializeHostingFeatures(System.Web.Hosting.HostingEnvironmentFlags hostingFlags, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException)   Unknown
    System.Web.dll!System.Web.Hosting.HostingEnvironment.Initialize(System.Web.Hosting.ApplicationManager appManager, System.Web.Hosting.IApplicationHost appHost, System.Web.Configuration.IConfigMapPathFactory configMapPathFactory, System.Web.Hosting.HostingEnvironmentParameters hostingParameters, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException) Unknown
    System.Web.dll!System.Web.Hosting.HostingEnvironment.Initialize(System.Web.Hosting.ApplicationManager appManager, System.Web.Hosting.IApplicationHost appHost, System.Web.Configuration.IConfigMapPathFactory configMapPathFactory, System.Web.Hosting.HostingEnvironmentParameters hostingParameters, System.Security.Policy.PolicyLevel policyLevel)  Unknown
    [AppDomain (DefaultDomain, #1) -> AppDomain (/LM/W3SVC/4/ROOT-1-130624548490751465, #2)]  
    System.Web.dll!System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)    Unknown
    System.Web.dll!System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters) Unknown
    System.Web.dll!System.Web.Hosting.ApplicationManager.GetAppDomainWithHostingEnvironment(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)   Unknown
    System.Web.dll!System.Web.Hosting.ApplicationManager.CreateObjectInternal(string appId, System.Type type, System.Web.Hosting.IApplicationHost appHost, bool failIfExists, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)    Unknown
    System.Web.dll!System.Web.Hosting.ProcessHost.StartApplication(string appId, string appPath, out object runtimeInterface)   Unknown
Handwriting answered 7/12, 2014 at 19:48 Comment(0)
S
5

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.

Shanna answered 20/6, 2009 at 10:1 Comment(1)
I've been having an issue where an IIS Reset causes an Access Denied to a specific old Microsoft DLL, and any subsequent spun-off new IIS temp folder for the app would fix it. Convinced that some other process is scanning and locking this specific file, I attempted your solution and forced a custom temporary directory for the application, and it appears to be working. Not a solution to the problem (the locking of the file), but a perfectly acceptable workaround that doesn't feel sloppy or hacky at all. Thankyou!Youngyoungblood
B
1

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).

Bubaline answered 4/6, 2009 at 15:26 Comment(0)
E
1

I found this when I was using ipersonation for another user in my web.config and the user didn't have rights. doh!

Esther answered 23/7, 2012 at 11:28 Comment(0)
A
0

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

Annunciata answered 27/5, 2009 at 19:10 Comment(0)
W
0

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.

Wolbrom answered 27/5, 2009 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.