System.IO.FileInfo cannot determine that a file exists on a server at the other end of a network

2.1k views Asked by At

This is my Visual Basic 2005 .NET code:

Dim imgflnm as string = "c:\testfolder\testdoc.txt"
Dim fltotest As New System.IO.FileInfo(imgflnm)
Dim tsrslt As Boolean
tsrslt = fltotest.Exists
System.Web.HttpContext.Current.Response.Write("source file exists result=" & tsrslt & "<br/>")

The above code returns tsrslt as true when it sees the file in question on a local drive-- same drive as the application. But on a mapped drive letter it cannot see the file and so tsrslt is evaluating as false.

I have tried the following:

DNS path

\\DPATSERVER\testfolder\testdoc.txt

ip path

\\192.xxx.yyy.zz\testfolder\testdoc.txt

dns path on a non-standard drive

\\DPATSERVER\e\testfolder\testdoc.txt

ip path on a non-standard drive (as above using ip instead of dns)
dns & ip on non-standard drive using $ after drive letter.

None of the above can see the file on the remote server. Any suggestions would be appreciated.

1

There are 1 answers

9
EJD On

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

  1. 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

  1. 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

  1. Right click on the folder that you are sharing and go to the security tab and give the user Everyone Access to that folder.