邁克,我相信你觀察到的是真的。我正在使用使用Azure TableStorage作爲數據存儲的ProfileProvider。我想從數據庫中獲取用戶配置文件的列表,並將它們與來自成員資格提供者的信息合併。 花了一些時間,直到我意識到以用戶名作爲參數調用ProfileBase.Create()執行對TableStorage的查找並且實際上檢索到與該用戶名相關聯的數據。就我而言,調用這個方法Create()是誤導,我期望加載()或Get()。 目前我的代碼看起來是這樣的:
public IEnumerable<AggregatedUser> GetAllAggregatedUsers()
{
ProfileInfoCollection allProfiles = this.GetAllUsersCore(
ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All)
);
//AggregatedUser is simply a custom Class that holds all the properties (Email, FirstName) that are being used
var allUsers = new List<AggregatedUser>();
AggregatedUser currentUser = null;
MembershipUser currentMember = null;
foreach (ProfileInfo profile in allProfiles)
{
currentUser = null;
// Fetch profile information from profile store
ProfileBase webProfile = ProfileBase.Create(profile.UserName);
// Fetch core information from membership store
currentMember = Membership.FindUsersByName(profile.UserName)[profile.UserName];
if (currentMember == null)
continue;
currentUser = new AggregatedUser();
currentUser.Email = currentMember.Email;
currentUser.FirstName = GetStringValue(webProfile, "FirstName");
currentUser.LastName = GetStringValue(webProfile, "LastName");
currentUser.Roles = Roles.GetRolesForUser(profile.UserName);
currentUser.Username = profile.UserName;
allUsers.Add(currentUser);
}
return allUsers;
}
private String GetStringValue(ProfileBase profile, String valueName)
{
if (profile == null)
return String.Empty;
var propValue = profile.PropertyValues[valueName];
if (propValue == null)
return String.Empty;
return propValue.PropertyValue as String;
}
有沒有更好的(更簡單的,更高性能的)的方式來
- 檢索配置文件提供所有的自定義配置文件信息,並
- 與它們合併會員提供者信息以顯示他們在管理員頁面?
我看過Web Profile Builder,但IMO僅通過生成代理類爲定製配置文件屬性提供設計時智能感知。
我沒有調用Save方法。我只是試圖檢索配置文件及其自定義屬性。 – 2009-07-15 16:18:17
順便說一句,如果你設置AutoSave = true,那麼你的配置文件將自動更新 – EvgeniyK 2013-06-19 11:01:08