仅具有所需参数的自定义 MembershipUser
我正在构建一个自定义 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 ;
}
正如您所看到的,我使用电子邮件作为会员资格的名称,并且不需要大多数其他参数。
有没有办法让通话更简单?我不想用空字符串和最小日期值初始化 MembershipUser。
提前致谢
I am building a custom MembershipProvider more precisely the GetUser function.
Therefor i have a custom 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)
{
}
}
In the GetUser function of the MembershipProvider i get the user data and put them into the 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 ;
}
As you can see i use the email as name for the MemberShip and i don't need most of the other parameters.
Is there a way to make the call simpler? I don't want to initalize the MembershipUser with empty Strings and minimal Date values.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以调整您的 CustomMembershipUser 来为您做“填充”吗?
它不能解决问题,但它会整理您的提供程序,这将成为
我认为您的 CustomMembershipUser 正在公开一些您没有向我们展示的其他属性。按照目前的情况,您只需返回一个 MembershipUser 即可。通过上述,您的 CustomMembershipUser 给您带来的唯一好处是您的 CustomMembershipProvider 中的结构更清晰
Could you adapt your CustomMembershipUser to do the 'padding' for you
It doesn't solve the problem but it will tidy up your provider which will become
I presume your CustomMembershipUser is exposing some additional properties that you are not showing us. As it stands you could just return a MembershipUser. With the above the only benefit your CustomMembershipUser gives you is the cleaner construction in your CustomMembershipProvider