Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET Accessing a file on the remote server 1

Status
Not open for further replies.

jgostomhandle

Programmer
Aug 6, 2009
1
US
A have a problem of accessing a file on the remote server (not Web server). Here is my code:

‘/APF/ is a vertual directory on the Web server asociated with the folder on the remote not Web server.
sPath = Server.MapPath("/APF/test.txt")
I also tried
sPath = "\\vcomnas2\sys\Extract\test.txt"
I also tried
sPath = "\\vcomnas2/sys/Extract/test.txt"

If File.Exists(sPath) Then
Response.Write("File exists <br>")
Else
Response.Write("File not found <br>")
End If

Dim sw As New StreamReader(sPath)
Response.Write(sw.ReadToEnd() & "<br>")
sw.Close()

This code perfectly works when I run it from Visual Studio. But when I run it from my local Web server or from the Company Web server Response.Write prints on the screen “File not found” and I got ASP message:
Access to ‘\vcomnas2sysExtracttest.txt’ is denied.
Please note that message removed slashes from the path. It is not an Access problem, it just cannot find the file, because when I provide a wrong path it still give me a message “Access to … is denied”. So my question is how should I specify the path on the remote (not Web server) to access a file on this path? Thank you in advance for your help.
John
 
If this is all working locally during development it is because the client and server are the same machine and you are authenticated as yourself on your local box, so you have access to all the resources you normally do. Once deployed to a remote server none of this exists (without configuration) because you are running under the asp.net account by default for IIS. And IIS does not require a user to be logged in to run. It's a windows component/service.

By default virtual directories should point to directories locally (not remote servers). by default the virtual directory will limit access to file/resources only within the virtual directory. This is all be design to reduce the visibility footprint and lower the possibility of malicious use.

I would host the file locally on the box running IIS. If the system need to access files outside the virtual directory, but locally on the box, you will need to configure the user account running IIS to have permissions. I use Windows Integrated Authentication, as it's simple and all my users run Windows.

If you need to access files on a remote machine, then not only do you need to run the website with a valid user account. You also need to configure delegation from the IIS server to the remote server to access the files. Delegation is configured in Active Directory.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top