您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

ASP.NET SQL配置文件提供程序-ProfileBase.Create()方法是否命中数据库?

ASP.NET SQL配置文件提供程序-ProfileBase.Create()方法是否命中数据库?

迈克,我相信您的观察是正确的。我正在使用将Azure TableStorage用作数据存储的ProfileProvider。我想从数据库获取用户配置文件列表,并将其与成员资格提供者的信息合并。我花了一段时间才意识到,以用户名作为参数调用ProfileBase.Create()会对TableStorage进行查找,并实际上检索 与该用户名关联的数据。就我而言,调用方法 Create() 会产生误导,我期望 Load()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仅通过生成代理类为自定义配置文件属性提供设计时的智能感知。

SQLServer 2022/1/1 18:53:05 有326人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶