File Access Permission Denied...

Posted on 2012-03-12
Last Modified: 2012-03-13

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.

Question by:JAruchamy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 42

Accepted Solution

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 (

Author Comment

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.
LVL 42

Expert Comment

ID: 37711795
what's the exception?
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

LVL 42

Expert Comment

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.

Author Comment

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.

Author Closing Comment

ID: 37717008
I created a new virtual directory and moved all the files there. Boom it worked.... thnx sedgwick for you answers though...

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…

695 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