I'm attempting to read the size of a backup file on a network server from a web page to determine if there's still enough space to store several days of backups.
The following code works on a local directory:
var directoryInfo = new DirectoryInfo( @"c:\AppFolder\" );
var file = directoryInfo.GetFiles()
.OrderByDescending( f => f.LastWriteTime )
.First()
;
var length = file.Length;
But when I try to access a network folder (e.g. \\server1.domain1\share\), I receive a System.UnauthorizedAccessException
: "Access to the path '\\server1.domain1\share\' is denied."
When logged in to the web server (Windows Server 2012 R2), my account can access the network share. I am fairly new to IIS 8.5. The web site was moved from IIS 6 on a Windows 2003 R2 server. I tried changing the identity of the Application Pool to each of the 4 options or even set it to my account, but I still get an access denied message. I used Process Monitor to see what account was accessing the network location. It seems to show that the correct identity is attempting to access the network location. But even on the entry which is set to my account, it gives an Access Denied message.
I tried giving permissions to the Application Pool identity as described here: IIS7 Permissions Overview - ApplicationPoolIdentity, but the Windows Server 2003 machine doesn't recognize IIS AppPool\website as a valid account.
Finally, I tried giving Everyone Full Control on the folder and the share. Even that doesn't work...
Updated diagnostic information:
Results of net share share
Share name share
Path c:\share
Remark
Maximum users No limit
Users USER1
Caching Manual caching of documents
Permission DOMAIN1\User1, READ
Results of icacls c:\share
:
c:\share NT AUTHORITY\NETWORK SERVICE:(OI)(CI)(F)
BUILTIN\Administrators:(I)(OI)(CI)(F)
DOMAIN1\User2:(I)(F)
CREATOR OWNER:(I)(OI)(CI)(IO)(F)
DOMAIN1\User3:(I)(OI)(CI)(M)
DOMAIN1\User1:(I)(OI)(CI)(RX)
NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
BUILTIN\Users:(I)(OI)(CI)(RX)
BUILTIN\Users:(I)(CI)(S,AD)
BUILTIN\Users:(I)(CI)(S,WD)
Successfully processed 1 files; Failed processing 0 files
Process Monitor:
Operation: CreateFile
Path: \\\\server1.domain1\\share1
Result: ACCESS DENIED
Detail: Desired Access: Read Data/List Directory, Synchronize,
Disposition: Open, Options: Directory, Synchronous IO Non-alert,
Open For Backup, Attributes: n/a, ShareMode: Read, Write, Delete,
AllocationSize: n/a, Impersonating: DOMAIN1\\User1
User: DOMAIN1\\User1