title: "Trust relationship between ... and the primary domain failed" in MVC5 Authentication
body: <p>I have a ASP .NET MVC5 application in which I am <strong>not</strong> using Windows Authentication.</p>
  
  <p>Everything was working fine until I tried running the application outside of the Domain in which it was being developed and (for whatever reason) got a:</p>
  
  <pre><code>The trust relationship between this workstation and the primary domain failed.
  </code></pre>
  
  <p>when I'm trying to do <code>User.IsInRole("Admin")</code>.</p>
  
  <p>I am using custom <code>Identity</code>, <code>Role</code>, <code>IdentityStore</code>, <code>RoleStore</code>, etc. from .NET's <a href="http://www.asp.net/identity" rel="noreferrer"><code>Identity</code></a> and I can see that the User and Role data is being retrieved from the (MongoDB) database correctly.</p>
  
  <p>There are plenty of questions regarding this issue, but they're from people who <strong>want to</strong> use Windows Auth. and impersonation in their MVC applications:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/2625509/with-windows-authentication-the-trust-relationship-between-the-primary-domain-a">With windows authentication, The trust relationship between the primary domain and the trusted domain failed, when calling IsInRole</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/7665710/how-to-configure-windows-authentication-impersonation-iis-7-mvc">How to configure Windows Authentication / Impersonation + IIS 7 + MVC</a></p></li>
  <li><p><a href="https://serverfault.com/questions/497586/the-trust-relationship-between-the-primary-domain-and-the-trusted-domain-failed">The trust relationship between the primary domain and the trusted domain failed</a></p></li>
  <li><p><a href="http://social.msdn.microsoft.com/Forums/en-US/75f7964b-c90f-487d-ae0c-82678dbe0c6e/myuserisinrolerole-name-throws-a-trust-relationship-error-on-windows-7?forum=vblanguage" rel="noreferrer">My.User.IsInRole("Role Name") throws a Trust Relationship error on Windows 7</a></p></li>
  </ul>
  
  <p>So why exactly am I getting this <code>SystemException</code> if I'm not using Active Directory and (as far as I know) not doing anything that might depend on the PC's domain? Am I missing some configuration (either in my <code>Web.config</code> or IIS Express)?</p>
  
  <h2>EDIT:</h2>
  
  <p>Ok, so narrowing it down a bit...</p>
  
  <p>My <code>User.IsInRole("Admin")</code> line is inside an <code>if()</code> statement in my <code>_Layout.cshtml</code> View (i.e., to know what to show in the nav. bar depending on the role).</p>
  
  <p>I now know I only get the error above when no user is authenticated and I'm not in the domain I used for dev. If I place a breakpoint on that line, I can see that the <code>User</code> object is is a <code>System.Security.Principal.WindowsIdentity</code> and its underlying <code>Identity</code> is <code>System.Security.Principal.WindowsIdentity</code>. </p>
  
  <p>On the other hand, if the user is authenticated, then the <code>User</code> object and ts <code>Identity</code> are <code>System.Security.Claims.ClaimsPrincipal</code> and <code>System.Security.Claims.ClaimsIdentity</code>.</p>
  
  <p>Why is it using Windows Identity at all (when unauthenticated) and how can I disable it?</p>