Solved

File Access Permission Denied...

Posted on 2012-03-12
6
263 Views
Last Modified: 2012-03-13
Hi,

I have ASP.NET page which is on Server1 and is trying to access a text file from a folder in Server2.

1. The ASP.Net code sits in a virtual directory on the IIS.

2. There is another virtual directory in the IIS which points to a location on the Server2 "\\Server2\Foldery\". I use this virtual directory and do Server.MapPath and get the loaction from this virtual directory. The path returned is right.

3. When I do a File.Exists(Path) it returns false, even though the file exsits on the Server2.

4. Can somebody help with the permissions that I have to give for the

a. Virtual Directory hosting the ASP.Net page. b. Virtual Directory poiting to the Server2. c. Folder on the Server2.

Thanks,
Jay
0
Comment
Question by:JAruchamy
  • 3
  • 3
6 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
its a permission issue, to detect the reason for this behavior i'd use Ciaran O''Donnell excellent approach which is comment out the File.Exists line of code and try to open the file with a file stream, along with try/catch block you'll find the real error message (http://bytes.com/topic/c-sharp/answers/534182-file-exists-always-returns-false).
0
 
LVL 2

Author Comment

by:JAruchamy
Comment Utility
Hi Sedgwick,

When I try FileStream fs = new FileStream(fromFile, FileMode.Open);

I get Access to the path "\\Server2\folder1\file.txt" is denied error.
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
what's the exception?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
i assume it fails because the ASPNET user doesn't have the permission to access the file.
goto the folder \\Server2\folder1\, Right Click -> Properties->Security ->Edit->Add , add everyone user to permission table.
0
 
LVL 2

Author Comment

by:JAruchamy
Comment Utility
I get a "unauthorizedaccessexception". I used Procmon.exe on the Server2 where the file is. Process monitor reports no hits from outside. So, it seems like the call from the Server1 is blocked by the IIS itself.
0
 
LVL 2

Author Closing Comment

by:JAruchamy
Comment Utility
I created a new virtual directory and moved all the files there. Boom it worked.... thnx sedgwick for you answers though...
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now