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
  • 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?
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP7 and Sql Server Windows 2008 R2 13 87
Syntax Error 2 47
Run time Error 4 34
.NET tools for adding thread safety to a web app? 3 17
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 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

15 Experts available now in Live!

Get 1:1 Help Now