问题描述
我写一个MVC 3应用程序,我想实现自己的自定义成员提供程序(以A preSS'临ASP.NET MVC框架3样以下)。
I am writing an MVC 3 application and I am trying to implement my own custom membership provider (following the sample in Apress' Pro ASP.NET MVC 3 Framework).
我创建了自定义类,从的MembershipProvider继承和(使用ReSharper的)实施与NotImplementedExceptions方法的所有27个。
I created my custom class, inherited from MembershipProvider and (using ReSharper) implemented all 27 of the methods with NotImplementedExceptions.
现在,我已经覆盖了ValidateUser方法作为这本书的状态,它工作正常,但我想使我的供应商更强大和实施其他方法(如设置MinRequiredPasswordLength和GetNumberOfUsersOnline)。
Now, I have overridden the ValidateUser method as the book states and it works fine, but I would like to make my provider more robust and implement the other methods (e.g. set MinRequiredPasswordLength and GetNumberOfUsersOnline).
有一些样本code,我可以用它来开始填充这些方法,我可以调整,以适应自己的DB /型号架构?
Is there some sample code that I can use to start populating these methods that I can tweak to fit my own DB/Model schema?
我当然可以使用试验和错误数字出来,但基本code样品将极大地帮助。
I can certainly use trial and error to figure it out, but a base code sample would greatly help.
编辑:
这个问题只是downvoted两次。如果你要downvote,请发表评论,为什么这样我就可以改善我的问题的工作。
This question was just downvoted twice. If you are going to downvote, please post a comment as to why so that I can work on improving my questions.
编辑2:
例如,对于下面的方法:
EDIT 2:For example, for the following method:
public override int GetNumberOfUsersOnline()
{
throw new System.NotImplementedException();
}
我可以尝试从头开始编写code看一些网络日志,确定用户的登录时间和近似的,如果他们仍然在,但是这将需要大量的时间,我要弄清楚。由于这一切code是微软为标准的SqlMembershipProvider写相同的接口,不存在(甚至从MS)code那里包含此方法是什么?如果是这样,我希望把它,修改它,以便它使用我的数据库架构,而不是ASPNETDB默认模式的。我想preFER有某种基地code的从工作。我认为这将是一个简单而相当标准的要求,但也许不是。
I can try to write code from scratch to look at some web log, determine the users login time and approximate if they are still on, but that will take a large amount of time for me to figure out. Since all this code is from the same interface that Microsoft wrote for the standard SqlMembershipProvider, isn't there code out there (even from MS) that contains this method? If so, I want take it, modify it so it uses my DB schema instead of the aspnetdb default schema. I would prefer to have some sort of base code to work from. I thought this would be a simple and fairly standard request, but perhaps not.
推荐答案
您不能使用默认提供的code为您定制供应商,这就是为什么你是根据实现自定义的,调整它的要求使用自己的数据库表等。
You can't use the default provider's code for your custom provider, that is why you are implementing a custom one, to tweak it according to your requirements, use your own db tables etc.
看看如何自定义成员资格, 提供商和的。还有就是如何使用自己的数据库来获取/设置会员信息的例子在那里。
Take a look at my blog posts about custom membership, custom role providers and custom membership user. There is an example there of how you can use your own database to get/set membership information.
这篇关于示例code用于创建自定义成员资格提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!