title: Microsoft ASP.NET Identity - Multiple Users with the same name
body: <p>I'm trying something quite exotic I believe and I'm facing a few problems, which I hope can be solved with the help of the users here on StackOverflow.</p>
  
  <h2>The story</h2>
  
  <p>I'm writing and application which requires authentication and registration. I've chosen to use <code>Microsoft.AspNet.Identity</code>. I've not used it a lot in the past, so don't judge me on this decision.</p>
  
  <p>The framework mentioned above contains a users table, that holds all the registered users.</p>
  
  <p>I've created a sample picture to show how the application will be working.</p>
  
  <p><img src="https://i.stack.imgur.com/AzxWJ.png" alt="enter image description here"></p>
  
  <p>The application consists out of 3 various components:</p>
  
  <ol>
  <li>Backend (WebAPI).</li>
  <li>Customers (Using the WebAPI directly).</li>
  <li>End Users (Using a Mobile App - iOS).</li>
  </ol>
  
  <p>So, I do have a backend on which Customers can register. There is one unique user per member, so no problem here.
  A customer is a company here and End Users are cliënts of the company.</p>
  
  <p>You might see the problem already, It's perfectly possible that <code>User 1</code> is a cliënt at <code>Customer 1</code> but also at <code>Customer 2</code>.</p>
  
  <p>Now, a customer can invite a member to use the Mobile application. When a customer does that, the end user does receive an e-mail with a link to active himself.</p>
  
  <p>Now, that's all working fine as long as your users are unique, but I do have a user which is a cliënt of <code>Customer 1</code> and <code>Customer 2</code>. Both customers can invite the same user and the user will need to register 2 times, one for each <code>Customer</code>.</p>
  
  <h2>The problem</h2>
  
  <p>In <code>Microsoft.AspNet.Identity</code> framework, users should be unique, which according to my situation, I'm not able to manage.</p>
  
  <h2>The question</h2>
  
  <p>Is it possible to add extra parameters to the <code>IdentityUser</code> that make sure a user is unique?</p>
  
  <h2>What I've done already</h2>
  
  <ol>
  <li><p>Create a custom class that inherits from <code>IdentityUser</code> and which includes an application id:</p>
  
  <pre><code>public class AppServerUser : IdentityUser
  {
      #region Properties
  
      /// &lt;summary&gt;
      ///     Gets or sets the id of the member that this user belongs to.
      /// &lt;/summary&gt;
      public int MemberId { get; set; }
  
      #endregion
  }
  </code></pre></li>
  <li><p>Changed my <code>IDbContext</code> accordingly:</p>
  
  <pre><code>public class AppServerContext : IdentityDbContext&lt;AppServerUser&gt;, IDbContext { }
  </code></pre></li>
  <li><p>Modified calls that are using the framework.</p>
  
  <pre><code>IUserStore&lt;IdentityUser&gt; -&gt; IUserStore&lt;AppServerUser&gt;
  UserManager&lt;IdentityUser&gt;(_userStore) -&gt; UserManager&lt;AppServerUser&gt;(_userStore);
  </code></pre>
  
  <p><em><code>_userStore</code> is off course of type <code>IUserStore&lt;AppServerUser&gt;</code></em></p></li>
  </ol>
  
  <p>However, when I do register a user with a username that is already taken, I still receive an error message saying that the username is already taken:</p>
  
  <pre><code>var result = await userManager.CreateAsync(new AppServerUser {UserName = "testing"}, "testing");
  </code></pre>
  
  <h2>What I do believe is a solution</h2>
  
  <p>I do believe that I need to change the <code>UserManager</code> but I'm not sure about it.
  I do hope that someone here has enough knowledge about the framework to help me out because it's really blocking our application development.</p>
  
  <p>If it isn't possible, I would like to know also, and maybe you can point me to another framework that allows me to do this.</p>
  
  <p><strong>Note:</strong> I don't want to write a whole user management myself because that will be reïnventing the wheel.</p>