title: Why asp.net core app uses different user than AppPool identity for Windows Authentication when connecting to SQL Server?
body: <p>I have deployed asp.net core 2.2 web app as a WebSite to IIS. I've set the application pool identity to ApplicationPoolIdentity:</p>
  
  <p>[<img src="https://i.stack.imgur.com/hZI4X.png" alt="IIS Screenshol[1]"></p>
  
  <p>I can see that <code>System.Security.Principal.WindowsIdentity.GetCurrent()</code> returns</p>
  
  <pre><code>IIS APPPOOL\MyCustomAppPool
  </code></pre>
  
  <p>But when I try to connect to SQL Server using connection string:</p>
  
  <pre><code>Server=localhost;Database=MyDadatabse;Trusted_Connection=True;
  </code></pre>
  
  <p>I get following error (ignore the german):</p>
  
  <blockquote>
    <p>SqlException: Fehler bei der Anmeldung für den Benutzer "CompanyDomain\ComputerName$".</p>
  </blockquote>
  
  <h1>Why it is not using the ApplicationPool identity?</h1>
  
  <p>Also note, that when I set custom username/password as the identity for application pool, it works.</p>