Whats the different between Membership.GetUser and Pr开发者_运维百科ofile.GetProfile if i wants to return a specific users information?
Membership and Profile are two completely different things. The Membership.GetUser providers authentication for an application and designates if the user is logged in, while the Profile is something that can be used to describe a user given properties that have been defined in the web.config that are type safe and customized for an applicaiton.
EDIT: To follow up a little more, a User object that is returned from Membership.GetUser() has information like username, password, security question / answer.
Profile information can contain anything that you want to know about a user, such as first name, last name, DOB, favorite type of ice cream, etc. Just as long as you set this up in the web.config:
<system.web>
<profile>
<properties>
<add name="firstName" type="string"/>
<add name="lastName" type="string"/>
<add name="DOB" type="DateTime"/>
<add name="favoriteIceCream" type="string"/>
</properties>
</profile>
</system.web>
The membership is the username, password and optionally a secret question / answer. You get a MembershipUser
back from Membership.GetUser()
.
The profile is your own customised profile object that you can configure to store whatever information you want in it.
Membership.GetUser
will return the user entry - e.g. the user with name, first name, e-mail address and so on.
Profile.GetProfile
will return a given user's profile settings, e.g. his preferences, config settings etc.
精彩评论