title: How do I implement custom Principal and Identity in ASP.NET MVC?
body: <p>I want to store extra information in the authenticated user so that I can have it easily accessible (like User.Identity.Id, for example), instead of just the name, since I'm planning on having that non-unique. </p>
  
  <p>So far I've gathered that I should look to implement custom Principal and/or Identity, but I'm not sure how to go about it. I've been looking for documentation and tutorials on the matter, but I've found related stuff in different places and I've found it a bit confusing.</p>
  
  <p>I have seen how to add custom info to the authentication cookie in the user data property, but I'd like to have the benefit of dependency injection for unit testing, which I can have with the principal and identity.</p>
  
  <p>What are the <strong><em>exact</em></strong> steps I need to consider if I want to implement my own Principal or Identity?</p>
  
  <p>What would be the simplest I could do in this scenario (just add the ID and keep all the defaults in place)? "Defaults" would include the default providers (membership, roles, etc.). </p>
  
  <p>I have seen the <a href="https://stackoverflow.com/questions/1064271/asp-net-mvc-set-custom-iidentity-or-iprincipal">other question</a>, but I'd appreciate answers that do not leave any holes in between, such as the roles magic strings in the AuthenticateRequest event in the examples. Instead I need to know how to add the roles from the default SqlRoleProvider to the current user: when and where to do it, and if I need to do anything else to connect my new classes with the other default providers. </p>
  
  <p>It'd be awesome to be able to go to a sample ASP.NET MVC 2 application (from the visual studio 2010 template, for example), make the edits and have it work.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I have edited the question to better show that I'm pretty much <strong><em>lost</em></strong> here, so I can't make do with too high level answers. </p>
  
  <p><strong>P.S.:</strong> It seems to me that it makes more sense to have the ID in the Identity instead of the principal, although I have, in a way, stated this before.</p>