Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent .NET from writing to C:\Windows\Temp

Tags:

I've got a C# application that I'm trying to push out to a distributed network. The application works fine locally (as always), but when I push it out to the network, it doesn't work because it can't write to the C:\Windows\Temp directory. I'm not actually calling any code that writes to that directory, but I imagine it is caused by my calls to a webservice, given the following exception:

Unable to generate a temporary class (result=1). error CS2001: Source file 'C:\WINDOWS\TEMP\cyalinh1.0.cs' could not be found error CS2008: No inputs specified '. Please see InnerException for more details.

Is there any way to prevent .NET from writing to the Temp directory? Is it a setting in the .config file?

UPDATE

Can SGEN be used to prevent the creation of those dynamically created classes from the webservice?

like image 490
Josh Avatar asked Nov 11 '09 19:11

Josh


2 Answers

It seems that webservices require read/write permission to %SystemRoot%\Temp (MSDN).

From here:

If you're running ASP.NET 2.0 or above, you can assign the required permissions with the command:

aspnet_regiis -GA MachineName\Account

This blog post contains instructions on how to change the location of the SystemRoot\Temp folder used for this (as well as instructions on how to use reflector to determine the setting in web.config to set for a situation like this)

like image 200
Yaakov Ellis Avatar answered Oct 12 '22 08:10

Yaakov Ellis


The problem you have here is that you are using some function which auto-generates temporary code. It needs a location to do this. So yes, while you can prevent it from writing code to that specific location, the only way to prevent it from generating code (that must be stored somewhere) is to not use a function that generates temporary classes.

like image 20
Erik Funkenbusch Avatar answered Oct 12 '22 07:10

Erik Funkenbusch