質問

私はカスタムメンバーシップロバイダーをより正確にGetUser機能を構築しています。

そのため、カスタムメンバーシップユーザーがいます。

public class CustomMemberShipUser : MembershipUser
{
    public CustomMemberShipUser (
        string providerName,
        string email,
        object providerUserKey,
        string name,
        string passwordQuestion,
        string comment,
        bool isApproved,
        bool isLockedOut,
        DateTime creationDate,
        DateTime lastLoginDate,
        DateTime lastActivityDate,
        DateTime lastPasswordChangedDate,
        DateTime lastLockoutDate
        ): base(
            providerName, email, providerUserKey, name, passwordQuestion,
            comment, isApproved, isLockedOut, creationDate, lastLoginDate,
            lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
    {
    }
}

MemberShipproviderのGetuser機能では、ユーザーデータを取得し、CustomMembershipUserに入れます。

public override MembershipUser GetUser(string email, bool userIsOnline)
    {
        User u = _db.Users.Where(x => x.Email == email).First();
        CustomMemberShipUser customUser = new CustomMemberShipUser (
                                        "CustomMemberShipUser ",
                                        u.Email, 
                                        u.id,
                                        u.Email, 
                                        "", 
                                        "", 
                                        true, 
                                        false, 
                                        u.CreateDate, 
                                        DateTime.MinValue, 
                                        DateTime.MinValue, 
                                        DateTime.MinValue, 
                                        DateTime.MinValue);
        return customUser ;
    }

ご覧のとおり、メールをメンバーシップの名前として使用していますが、他のパラメーターのほとんどは必要ありません。

通話をより簡単にする方法はありますか?空の文字列と最小限の日付値を使用して、メンバーシップユーザーを無視したくありません。

前もって感謝します

役に立ちましたか?

解決

カスタムメンバーシップユーザーを適応させて、あなたのために「パディング」を行うことができますか

   public class CustomMemberShipUser : MembershipUser
    {
        public CustomMemberShipUser (
            string email,
            object providerUserKey,
            ): base(
                "CustomMemberShipUser", email, providerUserKey, email, String.Empty,
                String.Empty, true, false, DateTime.MinValue, DateTime.MinValue,
                DateTime.MinValue, DateTime.MinValue, DateTime.MinValue)
        {
        }
    }

それは問題を解決しませんが、それはあなたのプロバイダーを片付けます

public override MembershipUser GetUser(string email, bool userIsOnline)
    {
        User u = _db.Users.Where(x => x.Email == email).First();
        CustomMemberShipUser customUser = new CustomMemberShipUser (u.Email, u.id);
        return customUser ;
    }

あなたのCustomMemberShipUserがあなたが私たちに見せていないいくつかの追加のプロパティを公開していると思います。現状では、メンバーシップユーザーを返すことができます。上記の唯一の利点は、カスタムメンバーシップユーザーが提供する唯一の利点です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top