After reading tons of similar posts I decided to came up with this one. Well, basically this problem is similar to many others, but somehow I can't make it work.
Here's the scenario, I have load balancing over 2 servers (servA and servB) and I need to force the app to create just on 1 of them. So I want to put the UNC path when I save files. I, obviously, have a problem creating files on the directory over the net.
If I run it with Cassini it's all good, I can access to the path cause it's logged with my account. As soon as I migrate the app on the development server it doesn't work anymore.
I know IIS uses the user associated with the app pool, so I checked that account (which is network_service) and added write privileges write on that folder.
Still not enough. What you think on "Everyone"?! It must work!
Oh, well, it's not.
Let's see some code:
Directory.CreateDirectory("\\\\my.ip.over.da.net\\c$\\inetpub\\wwwroot\\projfolder\\otherprojfolder\\test");
And this is the message I got when I try to create that folder.
{"Message":"Access to the path \u0027\\\\\\\\my.ip.over.da.net\\\\c$\\\\inetpub
\\\\wwwroot\\\\projfolder\\\\otherprojfolder\\\\test\u0027 is denied.","StackTrace":"
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at
System.IO.Directory.InternalCreateDirectory(String fullPath, String path,
DirectorySecurity dirSecurity)\r\n at System.IO.Directory.CreateDirectory(String path,
DirectorySecurity directorySecurity)\r\n at
NSC.Ajax.GetData.testgrid()","ExceptionType":"System.UnauthorizedAccessException"}
It's called via AJAX for easier testing, this is why the response is formatted that way.