title: Cannot write on a mapped drive using impersonation
body: <p>Basically I'm running the same problem as this post <a href="https://stackoverflow.com/questions/2669672/accessing-mapped-drives-when-impersonating-in-asp-net">Accessing mapped drives when impersonating in ASP.NET</a></p>
  
  <p>I'm working on a legacy website and I need to allow the admins to change the site's logo, banners, etc, from an image file on their desktops to a mapped drive on the server.</p>
  
  <p>So, their website is using impersonation whenever it needs to save on the drive, and it's working just fine; however I can't manage to make it work on their test environment nor in my test environment.</p>
  
  <p>¿Any ideas? I've double checked user and password (the code doesn't specify domain) and that's not the issue.</p>
  
  <p>Here's an excerpt from the code that handles impersonation:</p>
  
  <pre><code>public bool ImpersonateUser(String user, String password, String domain)
  {
      WindowsIdentity tempWindowsIdentity;
      IntPtr token = IntPtr.Zero;
      IntPtr tokenDuplicate = IntPtr.Zero;
  
      if (RevertToSelf())
      {
          if (LogonUserA(user, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0)
          {
              if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
              {
                  tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
                  impersonationContext = tempWindowsIdentity.Impersonate();
                  if (impersonationContext != null)
                  {
                      CloseHandle(token);
                      CloseHandle(tokenDuplicate);
                      return true;
                  }
              }
          }
      }
      //... rest of the code
  </code></pre>
  
  <p>And a -sanitized- test:</p>
  
  <pre><code>if (impUtility.ImpersonateUser("user", "password", string.Empty))
  {
      fu.SaveAs(@"C:\Images\" + imgName);
  }
  </code></pre>