title: Getting Access denied trying to read a file in App_Data in a ASP.NET project - Any pointers?
body: <p>I've an XML file stored in App_Data which is only used to read some configuration on startup.  When I attempt to open it within my code, I get an Access to the path ... is denied message.</p>
  
  <p>I'm having trouble understanding why, and how to solve it.  I guess in theory I should alter the permissions on the file (and directory), but this hasn't changed anything.</p>
  
  <p>To give a bit more background:
  1. Its a file bundled with the project, so the setup created by VS2008 writes it to the correct place during install.  I didn't think I'd need to do anything unusual post install such that the ASP.NET application would have access.
  2. When I've tried publishing this locally, I've not had any problems. - This is only on a test Windows 2003 server.
  3. I've ran a simple page to understand the effective user of IIS - It is NT AUTHORITY\NETWORK SERVICE.  I tried granting "Full Access" to this user to this file, and still it doesn't work.</p>
  
  <p>The code to open it is simple:</p>
  
  <pre><code>FileStream fs = new FileStream(Server.mapPath(s), FileMode.Open);
  </code></pre>
  
  <p>Where s is defined as '~/App_Data/myfile.xml</p>
  
  <p>I've even copied and pasted the full path &amp; filename (from the exception) and tried "dir" on it, and it is indeed present (to get around a typo for example).</p>
  
  <p>I've also tried running aspnet_regiis.exe /s as per some suggestions out there.</p>
  
  <p>This has me baffled.</p>