views:

4267

answers:

4

I'm experiencing this problem today on many different servers.

System.UnauthorizedAccessException: Access to the temp directory is denied.

The servers were not touched recently. The only thing that comes in my mind is a windows update breaking something.. Any idea?

This happens when trying to access a webservice from an asp.net page

System.UnauthorizedAccessException: Access to the temp directory is denied.  Identity 'NT AUTHORITY\NETWORK SERVICE' under which XmlSerializer is running does not have sufficient permission to access the temp directory.  CodeDom will use the user account the process is using to do the compilation, so if the user doesnt have access to system temp directory, you will not be able to compile.  Use Path.GetTempPath() API to find out the temp directory location.
       at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
       at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
       at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
       at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Evidence evidence)
       at System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
       at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
       at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
       at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
       at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
+2  A: 

Have you checked the permissions on the temp folder? In these cases, the easiest and quickest solution is usually to re-run the *aspnet_regiis -i* command to re-install the asp.net framework which also resets the permissions on the required folders. Failing that, try using Process Monitor to check what's going on and modify the permissions accordingly.

Mun
I had the same issue and using process monitor solved the problem for me. You only need to watch for file system activity and then look for w3wp.exe. The error message was something like permission denied and it gave the exact folder that w3wp was trying to write to. I gave the Network Service username read, write and list folder contents permissions.
Helephant
A: 

Whatever the reason for the sudden change, you can probably solve the problem using the steps described in the exception.

Call Path.GetTempPath to find out what it thinks the temporary directory is, it may not be what you think it is.

Go to that directory and give the user 'NETWORK SERVICE' the permissions it needs, probably Read/Write.

magnifico
A: 

Indeed its a web site running in IIS? and accessing a web service.

It's either running as ASPNET, anonymous, or impersonating the user connected or finally the web service itself is connecting as a 'user'.

Whichever user it is may not have access to the temp directory. Odd how nothing has changed :). However Windows Service packs can change security settings.

Robert
A: 

I had the same issue and none of the above solved our issue -- we restored service temporally by changing seeing what app pool each site was running under - going into app pools--> idenity tab and and changing user from Network Service to local user- while we figured out what the problem was(this is not recommended- so if you choose to do this make sure you understand the repercussions)

We then found a link about the Temp\TMP mappings and how to fix them -Which was not our issue

On another site (and as described in other answers) we used Path.GetTempPath() to see what the CLR was actually looking for it turned out to be

C:\WINDOWS\system32\config\systemprofile\Local Settings\Temp folder

We then used Process Monitor to verify this was in fact correct, when we changed the permission on this folder it worked correctly. We are still unsure as to why the CLR choose to stop using the default temp directory but we did find a link as to how it makes that decision. How GetTempPath is picked.

cgreeno