When you call the website and you use System.IO.File.Exists it is the IUSR account that is actually doing the request for the file.
The default for IIS is to use a local account for the web server and the account doesn't have permissions to access network share because it's a local account that only exists on that 1 machine and it does no exist on the other machine.
You need to configure the IIS application pool for your web site to run using a domain user account, and then give that account the permission to the network share. If you are not in a domain create the same user on both machines with the same password. Then run IIS as that user.
The less secure method is to allow Everybody access to the network share.
Configuring IIS Application Pool Identities
Example:
Domain or Network Account
- The same username and password is used to access any computer on the same network. If you change the password, it changes for all the computers.
Webserver
1.1 Change the application pool to use the username and password that you use to login with (1.) or a similar account on the same network. Typically you will create an account specifically on the network for this purpose that only has access to specific resources on the network. If you give this user access to the entire network then it means your entire network is now accessible by IIS huge security risk.
FileServer
1.2 Right click on the folder that you are sharing and go to the security tab. Confirm that the user (1.) has access to that folder.
Local Account
- This only exists on the 1 computer you can create the same user on another computer. But if you change the password on computer 1 it does not change the password on computer 2.
Webserver
2.1 Change the application pool to use the username and password that you use to login with (2.) or a an account created just for this use.
FileServer
2.1 Create the exact same user on this computer with the exact same credentials(2.,2.1) Right click on the folder that you are sharing
and go to the security tab. Confirm that the user (2.,2.1,2.2) has
access to that folder.
Less Secure Method
FileServer
- Right click on the folder that you are sharing and go to the
security tab and give the user Everyone Access to that folder.