title: Getting the current user id (not name) using forms authentication?
body: <p>Question:</p>
  
  <p>I'm playing around with forms authentication and my own custom membership provider.</p>
  
  <p>From what I see, I can get the current FormsIdentity by doing:</p>
  
  <pre><code>System.Web.Security.FormsIdentity veryFunny= (System.Web.Security.FormsIdentity)
      System.Web.HttpContext.Current.User.Identity;
  </code></pre>
  
  <p>And I can get the current Membership user doing this:</p>
  
  <pre><code>        var UserFromDb = System.Web.Security.Membership.GetUser();
  </code></pre>
  
  <p>And then I can get the userid by doing this:</p>
  
  <pre><code>var MyUserId = UserFromDb.ProviderUserKey;
  </code></pre>
  
  <p>What I find funny is that when I call Membership.GetUser(), then it calles this method in the membership provider</p>
  
  <pre><code>public override MembershipUser GetUser(string username, bool userIsOnline)
  </code></pre>
  
  <p>Which looks up the user information in the database.<br />
  So what I figured is that the .NET framework internally does </p>
  
  <pre><code>GetUser(System.Web.HttpContext.Current.User.Identity.Name, whatever);
  </code></pre>
  
  <p>which gets the user info from the database based on the USERNAME. 
  I find this disturbing, first because it is bad for performance when I have to lookup an entire user just to get the userid.</p>
  
  <p>Second, it's disturbing that i have to lookup the userid at all, because that's not what I would expect.</p>
  
  <p>Third, it's disturbing, because the username can be changed in the course of the program, and it's nonsense to have the user having to logout and login to do that.</p>
  
  <p>Now, to me this design sounds like nonsense.<br />
  But then again, microsoft also uses application name, group name, and username as primary key, which also really does not make a lot of sense.<br /></p>
  
  <p>So here my question:<br />
  Isn't there a way to get the user ID without a DB lookup ?<br /><br />
  Or is the entire Membership provider idea just so broken by design ?</p>
  
  <p>If it is so broken: <br />
  I saw that FormsIdentity has a string property called userdata. 
  If so, how can I use ASP.NET to save the userid in there ?</p>