views:

185

answers:

2

What are the differences between Membership.GetUser() and Context.User, and which is recommended for use in getting information about the current user?

+2  A: 

If you don't have membership configured for your site, getuser() won't yield anything.

Context.user is the identity token handed to the asp.net runtime, and will yield a user if any authentication aside from anonymous acces is configured fo the site.

Pierreten
Sounds like you're saying that Membership.GetUser() will get the user from the Membership (obvious enough), whereas Context.User will get the user from a broader scope - anything. So using windows auth, for example, yields nothing from Membership.GetUser(), but it DOES yield the windows user from Context.User. (And this appears to be the case from a quick test.)In that case, which is recommended if you are definitely using a Membership provider?
The MembershipProvider, in my experience; is mainly used when you need some flexibility in your authentication, you can even have an XMLMembershipProvider if needed. If you are using forms based authentication, a membershipprovider is probably the most painless way to go about it.
Pierreten
Looking more deeply into it, it looks like Context.User really gives minimal information. I think you're right about Membership.GetUser().Then again, there may be an efficiency drag from using Membership.GetUser() if all you need is information you can get from Context.User.
+2  A: 

Membership.GetUser implies the use of a MembershipProvider. It simply retrieves user information from whatever store is configured. (e.g. ActiveDirectory, SQL Server). Context.User is the IPrincipal security context for the current Request.

Thomas