NHibernate 和 ASP.NET 会员资格
我将 ASP.NET MVC 3 用于需要大量使用用户和角色的应用程序。
为了创建用户并分配角色,我通过 ASP.NET 会员资格使用标准流程。
在整个应用程序中,我使用 NHibernate 进行底层数据访问,除了使用默认 MembershipProvider 和 RoleProvider 实现的地方(在 AccountController 内部,它将调用委托给这些实现)。
我想使用 NHibernate 以便能够读取/编辑/修改由 ASP.NET 会员管理的表上的值。
我找到了两个解决方案:
为 MembershipProvider 和 RoleProvider 编写自定义 NHibernate 实现(或者甚至使用 这个)。这是最难的路径。
仅映射表(如此处所述),然后直接使用 NHibernate(尽管来自 AccountController 的任何默认操作仍将由默认提供程序处理)。
有什么建议/推荐吗?
I use ASP.NET MVC 3 for an application which makes heavy use or Users and Roles.
To create a user and assign role(s) I use the standard process via ASP.NET Membership.
Throughout the entire app I use NHibernate for the underlying data access except the places were the default MembershipProvider and RoleProvider implementations are used (inside the AccountController which delegates calls to those implementations).
I would like to use NHibernate in order to be able to read/edit/modify the values on that tables which are managed by ASP.NET Membership.
I found two solutions:
Write a custom NHibernate implementation for MembershipProvider and RoleProvider (or even use this one). That's the hardest path.
Map only the tables (as described here) and then use NHibernate directly (although any default actions from AccountController will still handled by the default providers).
Any suggestions/recommendations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经使用了您链接的自定义提供商,并取得了相当大的成功。我确实对它做了一些更改,以便它在其生命周期中使用单个会话。
如果您想使用 ASP.net 会员资格,我认为该方法是您最好的选择,主要是为了可移植性(它不依赖于数据库中存在的任何 SP)。我目前正在针对 MSSQL 和 Postgres 使用该链接中修改后的提供程序,没有任何问题,并且我也针对 MySQL 使用了它。
I've used the custom provider you link with pretty good success. I did make a few changes to it, so that it would use a single session for its lifetime.
If you want to use ASP.net membership I think that approach is your best bet, mainly for portability (it doesn't rely on any SP's being present in your database). I'm currently using the modified provider from that link against MSSQL and Postgres with no problems, and I've used it against MySQL as well.