user11850 user11850 - 2 years ago 133
ASP.NET (C#) Question

CS0016: Directory invalid error

I've been battling for two days tracking down a mysterious error when compiling an ASP.NET website. The error is the (quite famous) CS0016: "Unable to write to output file [filename] - directory is invalid".

I have discovered after two days of debugging that the cause of my problem is that the NetworkService somehow does not have the necessary rights to C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files. I have added "Everyone" with full rights to the folder - but I am still unable to access

http://localhost
and I can see using Process Monitor from SysInternals that the NetworkService account gets a "NAME NOT FOUND" when trying to create a DLL-file in that directory. My interpretation is that it does not have sufficient rights to the folder somehow.

However - when I fire up Visual Studio and attach a debugger the files are compiled using my domain user (JohnDoe for reference) and for some reason that works out fine - as if the domain user account contains further rights than I am unable to give the local users on my machine - which puzzles me a lot.

My two question to you guys are: Why is it that when I add "Everyone" with full rights to a folder the NetworkService still does not have the rights neccessary to create the temporary files needed? And which rights does my JohnDoe domain user have which I am unable to grant my local users on my machine?

Answer Source

You need to grant the NetworkService right permission to your system temp directory (the directory in the Temp variable). This is because the temporary asp.net files gets written to this temporary folder first before being moved to the ASP.NET Temporary Internet Files directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download