继承自EF中的MembershipUser类
我在项目中使用内置的 .net 身份验证,并在实体框架 4.0 中创建类实体。
我的班级有学生班、大学班和公司班。我的问题是我可以继承这些类的 System.Web.Security.MembershipUser 类吗? ef 类已经继承了 EntityObject 类,所以我不知道该怎么做?
谢谢
I am using the built in .net authentication in my project and am creating class entities in entity framework 4.0.
My classes are a Student, University and Company class. My question is can I inherit the System.Web.Security.MembershipUser class for these classes? The ef class already inherit the EntityObject class so I don't know how to do it?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题有点缺乏细节,但我尽力回答一下。
首先,您不想继承 MembershipUser 类。您可以(因为它是抽象的),但只有当您打算使用自己的逻辑和数据库表来存储验证字段时,您才会继承它。
您不会将会员资格分配给大学或公司类别,而是将其分配给这些实体的成员,例如学生是大学的成员,因为公司有员工。
学生或雇员都不会拥有他们的会员信息(在他们的数据库表中),但更有可能拥有与他们直接相关的信息(例如,雇员有工资单号码)。
学生和雇员都是 Person 类型(例如,他们都有姓名、地址等)
学生或员工可能是您的应用程序(网站、桌面等)的用户,但他们可能不是,或者他们可能被停用为用户,但您想保留他们的个人和信息供您记录的学生/员工信息。
用户将拥有常用信息,例如……用户 ID、用户名和密码等。但如果您打算在应用程序上放置 DisplayName,则您不想使用此实体。出于安全原因,我也不将会话信息放在用户上,而是使用 UserId(加密的 MD5 单向加密)和 SessionId 来验证我的用户会话,这意味着如果我的某些方式违反了安全性(SQL 注入)黑客将无法访问用户名和密码详细信息。无论如何,我离题了。
那么,MembershipUser 类是什么?它主要在您的 Authentication 对象中使用,该对象将具有诸如登录、更改密码、注销等方法。这些方法将调用
if (!Membership.ValidateUser('username', 'password')) return false; 。
如果您想使用自己的数据库表和实体框架调用会员资格,那么您需要实现一个自定义会员资格提供程序,覆盖所有标准方法并发出实体 DAO 请求(希望使用设计模式,例如存储库等) 这可能有风险且困难,但如果有经验的话,没什么大不了的。
否则,只需坚持使用标准的会员(用户)提供程序,将其所需的内容保留在 web.config 文件中并让它处理安全性,然后您就可以继续开发您的应用程序...
Pro Asp.Net 是一本好书MVC 框架...它涵盖了所有内容,包括单元测试、设计模式等。花一些钱的一个好方法是购买 GOF(四人帮)设计模式源代码...获得完整作品,最好 £ 60 花过。
我希望这有帮助。
休
Your question is a little lacking in detail but I have a go at answering.
To start you won't want to inherit from the MembershipUser class. You can (because its abstract) but you would only inherit from it if you were going to use your own logic and db tables to store the validation fields.
You wouldn't put Membership onto a University or Company class but on the members of those Entities e.g. a Student is a member of a University, as there are Employees to a Company.
Neither of the Student or Employee would have Membership information on them (within their db tables) but would more likely have information relating directly to them (e.g. an Employee has a Payroll number)
Student and Employee are both of type Person (e.g they both have Name, Address, etc.)
A Student or an Employee maybe a User of your Application (web site, desktop, etc.) but then they maybe not also, or they may be deactivated as a User but you want to keep their Person and Student/Employee information for your records.
A User will have the usual info like... UserId, Username and Password, etc. but you don't want to use this entity if you were going to put a DisplayName on the App. For security reasons, I also do not put Session information onto the User but use the UserId (encrypted MD5 one way encryption) and SessionId to validate my users Session, this means that if some how I did have a breach of security (SQL injection) the hacker would not be able to access Usernames and Password details. Anyway, I digress.
So, what is the MembershipUser class? It gets used mainly in your Authentication object which will have methods like... Login, ChangePassword, Logout, etc. These methods would call
if (!Membership.ValidateUser('username', 'password')) return false; etc.
If you wanted to use your own db tables and entityframework calls for the membership then you would look to implement a Custom Membership Provider, overriding all the standard methods and put you entity DAO requests (hopefully using Design Patterns e.g. Repositories etc.). This can be risky and difficult, but with experience not too big a deal.
Otherwise, just stick with the standard Membership (User) Provider, stick what it needs in the web.config file and have it deal with the security and you can get on with developing you Application...
a good book is Pro Asp.Net MVC Framework ... it goes through everything including unit-testing, design patterns, etc. Also a great way to spend some money is on the GOF (Gang of Four) design patterns source code... get the full works, best £60 spend ever.
I hope this helped.
Hugh
没有 EF 提供程序,但您可以编写自己的提供程序。
为您的 MembershipUser 派生类编写映射器类。
我在这里找到了一个很好的例子:
efmembership.codeplex.com
There is no EF provider, but you can write your own provider.
Write a mapper class for your MembershipUser derived class.
I found a nice example over here:
efmembership.codeplex.com