简体   繁体   English

NHibernate和ASP.NET成员资格

[英]NHibernate and ASP.NET Membership

I use ASP.NET MVC 3 for an application which makes heavy use or Users and Roles. 我将ASP.NET MVC 3用于大量使用的应用程序或用户和角色。

To create a user and assign role(s) I use the standard process via ASP.NET Membership. 要创建用户并分配角色,我使用ASP.NET成员资格的标准流程。

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). 在整个应用程序中,我使用NHibernate进行底层数据访问,除了这些地方是默认的MembershipProvider和RoleProvider实现(在AccountController内部委托调用这些实现)。

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. 我想使用NHibernate,以便能够读取/编辑/修改由ASP.NET成员资格管理的表上的值。

I found two solutions: 我找到了两个解决方案

  1. Write a custom NHibernate implementation for MembershipProvider and RoleProvider (or even use this one ). 为MembershipProvider和RoleProvider编写一个自定义的NHibernate实现(甚至使用这个实现 )。 That's the hardest path. 那是最艰难的道路。

  2. 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). 仅映射表(如描述在这里 ),然后直接使用NHibernate的(虽然从任何的AccountController默认动作将被默认提供商仍然处理)。

Any suggestions/recommendations? 有什么建议/建议吗?

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). 如果你想使用ASP.net会员资格,我认为这种方法是你最好的选择,主要是为了便携性(它不依赖于数据库中存在的任何SP)。 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. 我目前正在使用来自该链接的修改后的提供程序对MSSQL和Postgres没有任何问题,我也将它用于MySQL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM