gpt4 book ai didi

asp.net - 仅具有所需参数的自定义 MembershipUser

转载 作者:行者123 更新时间:2023-12-01 21:58:57 25 4
gpt4 key购买 nike

我正在构建一个自定义 MembershipProvider,更准确地说是 GetUser 函数。

因此我有一个自定义的 MembershipUser。

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 ;
}

如您所见,我使用电子邮件作为 MemberShip 的名称,并且不需要大多数其他参数。

有没有办法让通话更简单?我不想用空字符串和最小日期值初始化 MembershipUser。

提前致谢

最佳答案

您能否调整您的 CustomMembershipUser 来为您进行“填充”

   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 暴露了一些您未向我们展示的其他属性。按照目前的情况,您只需返回一个 MembershipUser 即可。通过上述,您的 CustomMembershipUser 给您带来的唯一好处是您的 CustomMembershipProvider 中的结构更加简洁

关于asp.net - 仅具有所需参数的自定义 MembershipUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6303012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com