title: IIS Cannot access file, but user logged on via same account can
body: <p>We recently moved a web application over to a new machine. The old one was Win2k, IIS 6.</p>
  
  <p>New machine is Win Server 2003, IIS 7.</p>
  
  <p>The application was previously looking for image files on a network share, mapped as drive letter <code>O</code>. This was working fine.</p>
  
  <p>Upon moving, the app was no longer able to access these files. The portion of the app that tries to access the <code>O:</code> drive files is a compiled CGI, so I'm not sure what it looks like on the inside. I could probably get access to the source, but I decided to try a very simple test to try and see what's wrong first.</p>
  
  <p>To try and troubleshoot, I created a small C# program that tries to access a test file locally (on the <code>C:</code> drive), then looks for a file on the <code>O:</code> drive, then the <code>Z:</code> drive, and then looks for the same file as on the <code>O:</code> drive, but uses a UNC path instead of relying on a drive mapping. Finally, it prints out the domain and username it's running under. I registered this as a CGI via the same method that was used to register the original EXE that got moved over from the old server.</p>
  
  <p>The file on the <code>C:</code> drive is read without problem, but the other files cannot be read. And the C# app tells me it's running as account <code>Washington$</code> under the <code>Traffic</code> domain. The account I THOUGHT was in use was <code>Washington</code> (note that one has a <code>$</code> at the end, one does not).</p>
  
  <p>Right after I tried that and got the failures, I logged on via Remote Desktop as User: <code>Washington</code> on the <code>Traffic</code> domain, and was able to see the test file on the UNC path without any problem (tested in a command prompt, via <code>dir \\trsystem\images2\testFile.txt</code>.</p>
  
  <p>I'm not tied to the mapped drive letters; in fact I'd like to switch over to use the UNC path.</p>
  
  <p>Also, I'm pretty new to Windows domains and IIS management/administration. This problem could have a very basic root cause that I'm just unaware of or overlooking.</p>
  
  <p>The output of my program is below:</p>
  
  <pre>
  
  --- Success opening C drive file! ---
  Failed to open O drive file:
  
  System.IO.DirectoryNotFoundException: Could not find a part of the path 'O:\testFile.txt'.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
     at System.IO.File.OpenRead(String path)
     at Testing.Main()
  
  Failed to open Z drive file:
  
  System.IO.DirectoryNotFoundException: Could not find a part of the path 'Z:\testFile.txt'.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
     at System.IO.File.OpenRead(String path)
     at Testing.Main()
  
  Failed to open UNC file:
  
  System.UnauthorizedAccessException: Access to the path '\\trsystem\images2\testFile.txt' is denied.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
     at System.IO.File.OpenRead(String path)
     at Testing.Main()
  ---------- ---------- ----------
  Domain Name is:TRAFFIC
  UserName is:WASHINGTON$
  
  </pre>
  
  <p>And, the program itself (note that this is my first foray into C#; and thrown together based on web examples so please overlook it's uglyness):</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Security.Permissions;
  
  class Testing{
      public static void Main()    {
          bool cFile = true;
          bool oFile = true;
          bool zFile = true;
          bool uncFile = true;
  
          try{
              //Try to open the file on the C drive
              File.OpenRead("C:\\testFile.txt");
          }
          catch (Exception e){
              Console.WriteLine("Failed to open C drive file:\n");
              Console.WriteLine(e.ToString());
              cFile = false;
          }
          if (cFile)
          {
              Console.WriteLine("\n\n--- Success opening C drive file! ---\n\n");
          }
  
          Console.WriteLine("\n\n");
  
          try
          {
              //Try to open the file on the O drive
              File.OpenRead("O:\\testFile.txt");
          }
          catch (Exception f)
          {
              Console.WriteLine("Failed to open O drive file:\n");
              Console.WriteLine(f.ToString());
              oFile = false;
          }
          if (oFile)
          {
              Console.WriteLine("\n\n--- Success opening O drive file! ---\n\n");
          }
  
          Console.WriteLine("\n\n");
  
          try
          {
              //Try to open the file on the Z drive
              File.OpenRead("Z:\\testFile.txt");
          }
          catch (Exception g)
          {
              Console.WriteLine("Failed to open Z drive file:\n");
              Console.WriteLine(g.ToString());
              zFile = false;
          }
          if (zFile)
          {
              Console.WriteLine("\n\n--- Success opening Z drive file! ---\n\n");
          }
  
          Console.WriteLine("\n\n");
  
          try
          {
              //Try to open the file via UNC
              File.OpenRead("\\\\ntsys\\images2\\testFile.txt");
          }
          catch (Exception g)
          {
              Console.WriteLine("Failed to open UNC file:\n");
              Console.WriteLine(g.ToString());
              uncFile = false;
          }
          if (uncFile)
          {
              Console.WriteLine("\n\n--- Success opening UNC file! ---\n\n");
          }
          Console.WriteLine("\n\n");
          Console.WriteLine("---------- ---------- ----------\n\n");
          string domainName = Environment.UserDomainName;
          string userName = Environment.UserName;
          Console.WriteLine("Domain Name is:" + domainName + "\n");
          Console.WriteLine("UserName is:" + userName + "\n\n");
      }
  }
  </code></pre>
  
  <p>Thanks in advance for any assistance or troubleshooting ideas!</p>