0

プロパティで検索するユーザー名を持つすべてのユーザーを取得しようとしています。

MembershipUserCollection users = Membership.FindUsersByName(txtSearchName.Text + "%");
datalist1.DataSource = users;
datalist1.DataBind();

//In the datalist
<asp:Label ID="UserName" runat="server" Text='<%# Eval("Username") %>'></asp:Label>

上記のコードは機能します。データベースから任意のユーザー名を入力すると、表示されます。ただし、firstname、lastnameなどのwebconfigで指定したすべてのプロファイルプロパティも必要です。

4

3 に答える 3

0

私は常にこれをビジネス ロジック レイヤーで処理してきました。UserAccountプロファイル属性を拡張してプロパティを追加するには、カスタム タイプを作成する必要があります。

    public static Profile GetProfile() {
        Profile profile = null;
        if (HttpContext.Current.User.Identity.IsAuthenticated) {
            var user = Membership.Provider.GetUser(HttpContext.Current.User.Identity.Name, false);
            if (user != null) {
                // an AD user who is already authed
                profile = ReferralsData.GetProfilesByProviderKey(user.UserName) ?? new Profile();
                profile.UserAccount = user;
            }
        }
        return profile;
    }
于 2012-08-21T12:08:20.497 に答える
0
var profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.Authenticated)
datalist1.DataSource = profiles;
datalist1.DataBind();


<asp:Label ID="UserName" runat="server" Text='<%# Eval("UserName") %>'></asp:Label>
<asp:Label ID="FirstName" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label>
<asp:Label ID="LastName" runat="server" Text='<%# Eval("LastName") %>'></asp:Label>
于 2012-08-21T11:59:57.893 に答える
0

プロファイル プロバイダー クラスを介してプロファイル プロパティにアクセスできます。

var profile = ProfileBase.Create(userName);
var firstName = profile["FirstName"] as string;
var lastName = profile["LastName"] as string;
于 2012-08-21T12:00:29.867 に答える