问题
I have stored profile info using this code
ProfileBase userprofile = HttpContext.Current.Profile;
userprofile.SetPropertyValue("FirstName", TextBoxFirstName.Text);
userprofile.SetPropertyValue("LastName", TextBoxLastName.Text);
userprofile.SetPropertyValue("AboutMe", TextBoxAboutMe.Text);
userprofile.SetPropertyValue("ContactNo", TextBoxContactNo.Text);
and in web.config
<profile enabled="true" defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="FirstName" type="String" />
<add name="LastName" type="String" />
<add name="AboutMe" type="String" />
<add name="ContactNo" type="String" />
</properties>
</profile>
The profile info is stored and every user is able to view his own profile info using something like this
TextBoxFirstName.Text = HttpContext.Current.Profile.GetPropertyValue("FirstName").ToString();
How to fetch profile info of other user say a user types the username of other user in a text box and clicks a button?
回答1:
The below code can fetch all the user profile. Pls customise some more so that you achive your objective.
1 public object[] GetPropertyValues(string propertyName)
2 {
3 int totRec;
4 List<object> values = new List<object>();
5 ProfileInfoCollection pic = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.Authenticated, 0, 1000, out totRec);
6
7 foreach (ProfileInfo pi2 in pic)
8 values.Add(ProfileBase.Create(pi2.UserName).GetPropertyValue(propertyName));
9
10 return values.ToArray();
11 }
12
You can get more information in http://forums.asp.net/t/1232593.aspx
回答2:
What I was looking is this below, it fetches all the profiles of the specified user.
ProfileInfoCollection pic = System.Web.Profile.ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.All, "username");
foreach (ProfileInfo pi2 in pic)
{
//ProfileBase.Create(pi2.UserName).GetPropertyValue("FirstName").ToString();
ListBox1.Items.Add(ProfileBase.Create(pi2.UserName).GetPropertyValue("FirstName").ToString());
//(new ProfileBase) Create(pi2.UserName)).GetPropertyValue("FirstName");
}
Answer by Hojo has been very helpful, thanks.
来源:https://stackoverflow.com/questions/2479187/how-can-a-user-view-profile-info-of-other-users