title: Spoof IIS Express App Pool Identity for Integrated Security
body: <p>In order to keep application secrets out of source code I want to use Integrated Security to connect my ASP.NET MVC application to SQL Server. However, IIS Express uses my development machine's account as the Identity for Integrated Security, which has different permissions from the AppPoolIdentity on production. I want to connect to SQL server using the same permissions in development as in production, which seems like something that should be easy to do, but I have had no luck.</p>
  <p>Apparently it is impossible to set the Identity used by IIS Express except using &quot;runas&quot; which I could not get to work: <a href="https://stackoverflow.com/questions/5331206/how-to-run-iisexpress-app-pool-under-a-different-identity">how to run iisexpress app pool under a different identity</a></p>
  <p>Things I've tried:</p>
  <ol>
  <li><p>IIS Express</p>
  <ul>
  <li>Create a User in &quot;Edit local users and groups&quot; and add it to &quot;IIS_IUSRS&quot; group.</li>
  <li>Create AppPool in IIS Express manager (Jexus manager)</li>
  <li>Setting AppPool &gt; ProcessModel &gt; Identity to newly created User, which fails.</li>
  <li>(However setting AppPool Identity works in IIS Manager (not express))</li>
  <li>Create site and configure path and ApplicationPool</li>
  <li>Application successfully launches through Jexus manager, however still using my Windows account like it does launching from Visual Studio</li>
  </ul>
  </li>
  <li><p>IIS</p>
  <ul>
  <li>Create app pool and log in as newly created user (succeeds unlike Jexus manager)</li>
  <li>Create and configure site to use https and IIS Express development cert</li>
  <li>Get 500 error when trying to launch the same way as with Jexus manager</li>
  <li>I would rather launch the app from Visual Studio anyway</li>
  </ul>
  </li>
  <li><p>Impersonation</p>
  <ul>
  <li>Requires credentials in <code>web.config</code> defeating the purpose of Integrated Security</li>
  </ul>
  </li>
  <li><p>It's important we manage secrets internally so Azure Key vault or other similar 3rd-party solutions are off the table.</p>
  </li>
  </ol>
  <p>It's beginning to seem impossible to configure IIS Express AppPools to use an Identity other than the currently logged in user: <a href="https://social.msdn.microsoft.com/Forums/en-US/cc19e0a9-98be-4a45-9cbc-2fb8bdbb9938/which-applicationpool-does-iis-express-debug-use?forum=aspgettingstarted" rel="nofollow noreferrer">Link1</a> and <a href="https://stackoverflow.com/questions/5331206/how-to-run-iisexpress-app-pool-under-a-different-identity">Link2</a>. The second link describes a method using &quot;runas&quot; from cmd as Admin but using <code>System.Security.Principal.WindowsIdentity.GetCurrent().Name</code> to check the ApplicationPool identity still shows my logged in Identity, not the one I used in the &quot;runas&quot; command.</p>
  <p>What are my options? I would like to use Integrated Security for both dev and prod, with the same permissions on each. Is this possible? Is there an equivalent workaround?</p>