自定义成员资格提供者*没有*数据库? [英] A Custom Membership Provider *Without* a Database?

查看:219
本文介绍了自定义成员资格提供者*没有*数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找各地的各种做题,博客等等关于MVC 4.更改会员供应商虽然我喜欢很多的变化和对事物的简化(尤其是超出任何─箱体外部登录支持),我目前还无法找到一个看似简单的事情...

I've been looking around various SO questions, blog posts, and so forth regarding the changes to membership providers in MVC 4. While I like many of the changes and the simplification of things (particularly the out-of-the-box external login support), I'm as yet unable to find one seemingly-simple thing...

我如何可以覆盖与使用其他数据源一个自定义的成员资格/角色提供?

How can I override the membership/role provider with a custom one that uses another data source?

我不希望替换 WebSecurity 或任何激烈的,因为它处理的是,我希望它处理的事情。 (cookie管理,例如。)我不想做任何将打破外​​部登录提供商现有的支持,我的应用程序使用那些在本地登录一起。所有我希望做的是会员制度和它背后的数据库之间的插话和定制数据抓取。

I don't want to replace WebSecurity or anything that drastic, since it handles all of the things I want it to handle. (Cookie management, for example.) I don't want to do anything that will break the existing support for external login providers, as my application uses those in conjunction with local logins. All I'm looking to do is interject between the membership system and the database behind it and customize that data fetching.

这是默认创建的表是:


  • 用户配置

  • webpages_Membership

  • webpages_OAuthMembership

  • webpages_Roles

  • webpages_UsersInRoles

虽然这样的作品,我有理由摘要:一些自定义的对象身后,打破应用程序和数据库之间的耦合。 (基本上,我有一些自定义的域模型完整的商业逻辑应该处理这一切,我希望会员/角色系统中使用这些模型,而不是数据库。这些模型可以从数据库中得到他们的持续性数据,搞不好不,这不应该的问题。)

And while that works, I have cause to abstract this behind some custom objects and break the coupling between the application and the database. (Basically, I have some custom domain models full of business logic which should handle all of this, and I want the membership/role system to use those models instead of the database. Those models might get their persisted data from a database, they might not. That shouldn't matter.)

大多数我找到了自定义的参考声称,它很容易做到,我所要做的就是修改用户配置模式,包括各种调用我的新的自定义字段,并更新调用 InitializeDatabaseConnection 把它指向我的数据库架构。

Most of the references I find for customization claim that it's easy to do, all I have to do is modify the UserProfile model, include my new custom fields in various calls, and update the call to InitializeDatabaseConnection to point it to my database schema.

但我不会使用一个数据库。 (或者,更准确地说,至于应用层关注有没有这样的东西作为一个数据库,只有我的域模型。),以便轻松定制并没有真正改变任何东西。

But I'm not using a database. (Or, more specifically, as far as the application layer is concerned there's no such thing as a database. Only my domain models.) So that easy customization doesn't really change anything.

有没有办法实行会员制和数据库之间插话,所以我可以为现有的会员提供一个自定义的数据提供者?

Is there a way to interject between the membership system and the database so I can make a custom data provider for the existing membership provider?

推荐答案

您应该能够创建一个自定义的 SimpleRoleProvider ,并通过修改web.config中像这样把它插入到你的应用程序:

You should be able to create a custom SimpleRoleProvider and plug it into your application by modifying the web.config to something like this:

<add name="SimpleRoleProvider" type="MyCustomRoleProvider.SimpleRoleProvider, MyCustomRoleProvider"/>

其中的 MyCustomRoleProvider 的是,大会的包含您的执行名义的 SimpleRoleProvider

Where MyCustomRoleProvider is the name of the assembly that contains your implementation of SimpleRoleProvider.

然后就撕了初始化的 SimpleMembership 的。 本文介绍如何简化初始化过程为的 SimpleMembership 的。基本上是从的的AccountController 的删除的 InitializeSimpleMembership 的属性和移动初始化在Global.asax的Application_Start方法。但是,在你的情况,你会希望添加您的自定义所需的任何初始化的 SimpleRoleProvider 的,如果有任何需要的。

Then just rip out the initialization for SimpleMembership. This article describes how to simplify the initialization process for SimpleMembership. Basically remove the InitializeSimpleMembership attribute from the AccountController and move the initialization to the Global.asax Application_Start method. But in your case you would want to add any initialization required for your custom SimpleRoleProvider, if there is any required.

有关实施你所描述你将极有可能还可以创建一个自定义的<一个href=\"http://msdn.microsoft.com/en-us/library/webmatrix.webdata.simplemembershipprovider%28v=vs.111%29.aspx\"相对=nofollow> SimpleMembershipProvider 。

For the implementation your are describing you will most likely have to also create a custom SimpleMembershipProvider.

这篇关于自定义成员资格提供者*没有*数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆