Solved

File Access Permission Denied...

Posted on 2012-03-12
6
267 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
ID: 37711693
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
ID: 37711738
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
ID: 37711795
what's the exception?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 42

Expert Comment

by:sedgwick
ID: 37711815
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
ID: 37712102
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
ID: 37717008
I created a new virtual directory and moved all the files there. Boom it worked.... thnx sedgwick for you answers though...
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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