I ran into a very simple problem today that, unfortunately, had a somewhat complex solution. A user’s Active Directory login name had changed, and I needed to update his record in a web application which uses Membership to handle its logins.
Now, of course, the easiest way to uniquely identify your users is by username. You can easily get the ID of the currently logged in user from User.Identity.Name. Of course, as I discovered, this is a Bad Idea, because now I have to update 14 fields in 11 tables.
Instead, it’s best to user the ProviderUserKey property of the MembershipUser. This means it takes one extra step to get the current user’s ID: Membership.GetUser(User.Identity.Name).ProviderUserKey
On the other hand, you can pass the ProviderUserKey value into Membership.GetUser just like you did the username.