c#-实现自定义会员用户和自定义会员提供程序
作者:互联网
参考文献
http://msdn.microsoft.com/en-us/library/6tc47t75%28v=VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms366730.aspx
题
在标题为“创建自定义会员资格提供者”正下方的第二个链接中,您会注意到他们提到了这一点
You will need to create a custom membership provider that supports
both your custom membership user type, and your custom membership data
store. The GetUser and CreateUser methods of the custom membership
provider can be written to return objects of the custom membership
user type.
以下是我的具有自定义字段的自定义成员身份用户
自定义会员用户
public class CustomMembershipUser : MembershipUser
{
//private fields for internal use
private bool _isMarried;
private bool _hasLicense;
private string _address;
private int _userId;
//public fields for use by end user
public int UserId
{
get { return _userId; }
set { _userId = value; }
}
...
自定义会员资格提供者
public class CustomMembershipProvider : MembershipProvider
{
.....
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
throw new NotImplementedException();
}
....
我完全按照他们的要求去做,像这样返回我的自定义类型的会员用户
public override **CustomMembershipUser** CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
但是后来我被IDE抱怨
覆盖MembershipProvider.CreateUser时无法更改返回类型.那我现在该怎么办
>创建另一个具有相同参数的方法并返回自定义成员资格用户?
>我不需要密码问题,安全性问题字段该如何消除?
解决方法:
您需要在函数中返回MembershipUser实例,这是它的返回类型.目前,它没有返回应该返回的内容.
在codeproject上有一个很好的教程:Custom Membership Providers.您可能会发现它对了解您不正确的地方很有帮助.
标签:membership-provider,override,asp-net-membership,c,membershipuser 来源: https://codeday.me/bug/20191202/2085941.html