title: Impersonation in ASP.NET web application does not work when running on IIS
body: <p>I am working on ASP.NET 4.0 MVC3 web application that works in intranet environment. The application makes use of Windows authentication. Its application pool is run by domain user that has spn set on a domain controller. Authentication works using Kerberos (on IE and Firefox after some additional configuration).</p>
  
  <p>Now I want to upload files to sharepoint, but it's important for me to upload the file as the user currently logged in into the application (so the file is created on Sharepoint with his/her credentials).</p>
  
  <p>I have the following code in <code>ResourceExists(Uri uri)</code> function:</p>
  
  <pre><code>'...
      Dim identity As System.Security.Principal.WindowsIdentity = HttpContext.User.Identity
      Dim impersonationContext = identity.Impersonate()
      response = request.GetResponse()
      impersonationContext.Undo()
  '...
  </code></pre>
  
  <p>This works when running locally, but when I deploy to the server I get the exception:</p>
  
  <pre><code>System.Net.WebException: The remote server returned an error: (401) Unauthorized.\r\n   at WebDav.WebDavClient.ResourceExists(Uri uri)\r\n   at Website.Website.WebdavController.Upload(HttpPostedFileBase file, UploadViewModel vm)
  </code></pre>
  
  <p>I read something about passing on the credentials, that is not possible with NTLM, but I am sure I am using Kerberos (I checked the headers with wireshark and fiddler) and I see the following:</p>
  
  <pre><code>Authorization: Negotiate YIIFpQYGKwYBBQUCoIIFmTCCBZWgJDAiBgkqhkiC9x...
  </code></pre>
  
  <p>Any ideas why the impersonation does not work when running on the IIS server?</p>