MVC4应用程序 - 如何删除实体框架并实现SimpleMembershipProvider?

时间:2022-04-30 14:30:35

I am trying to use ASP.NET MVC4 to manage Forms Authentication and OAuth (Facebook), and take care of the browser sessions.

我正在尝试使用ASP.NET MVC4来管理表单身份验证和OAuth(Facebook),并负责浏览器会话。

Yet I would like to manage all the users's data (and actually all the data) in a NoSQL data store. Since I already have a Data Access Layer library for that store, I thought I should not use Entity Framework at all.

但我想在NoSQL数据存储中管理所有用户的数据(实际上是所有数据)。由于我已经拥有该商店的数据访问层库,我认为我根本不应该使用实体框架。

My thought was: 1. Disable EntityFramework, all "default" data connections and tables used to implement "Membership". 2. Implement my own provider on top of NoSQL, by inheriting my own provider class from SimpleMembershipProvider (to support both Forms and OAuth authentication) 3. Configure system not to use Roles provider for now (no requirements to manage roles yet)

我的想法是:1。禁用EntityFramework,所有“默认”数据连接和用于实现“成员资格”的表。 2.通过从SimpleMembershipProvider继承我自己的提供程序类(以支持Forms和OAuth身份验证),在NoSQL之上实现我自己的提供程序.3。配置系统暂时不使用Roles提供程序(还没有管理角色的要求)

Unfortunately, I wasn't able to do "Step 1", i.e. get read from all the default connections and tables.

不幸的是,我无法执行“步骤1”,即从所有默认连接和表中读取。

I did manage to register and use my own SimpleMembershipProvider implementation, but there is some code around that keeps calling the "default connection".

我确实设法注册并使用我自己的SimpleMembershipProvider实现,但是有一些代码保持调用“默认连接”。

Example of exception I am getting with my provider, when disabling RoleManager in the web.config:

在web.config中禁用RoleManager时,我与提供程序一起获得的异常示例:

  InnerException: System.InvalidOperationException
       HResult=-2146233079
       Message=The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588
       Source=MvcApplication5
       StackTrace:
            at MvcApplication5.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\Users\max\Documents\Visual Studio 2012\Projects\MvcApplication2\MvcApplication5\Filters\InitializeSimpleMembershipAttribute.cs:line 45
       InnerException: System.Configuration.Provider.ProviderException
            HResult=-2146233088
            Message=The Role Manager feature has not been enabled.
            Source=System.Web
            StackTrace:
                 at System.Web.Security.Roles.EnsureEnabled()
                 at System.Web.Security.Roles.get_Provider()
                 at WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables)
                 at WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables)
                 at MvcApplication5.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\Users\max\Documents\Visual Studio 2012\Projects\MvcApplication2\MvcApplication5\Filters\InitializeSimpleMembershipAttribute.cs:line 41
            InnerException: 

What's the recommended way of doing that? (in web.config?) If there is a fundamental flaw or misunderstanding in my plan, please let me know.

建议的方法是什么? (在web.config中?)如果我的计划存在根本缺陷或误解,请告诉我。

Thanks for any hint.

谢谢你的任何提示。

2 个解决方案

#1


1  

SimpleMembershipProvider doesn't use Entity Framework. Instead, it has own SQL operations.

SimpleMembershipProvider不使用Entity Framework。相反,它有自己的SQL操作。

You can look at the source of SimpleMembershipProvider.cs

您可以查看SimpleMembershipProvider.cs的来源

If you want to implement a custom provider (to support both Forms and OAuth authentication), you want to override ExtendedMembershipProvider by coping some codes from SimpleMembershipProvider.

如果要实现自定义提供程序(以支持Forms和OAuth身份验证),您希望通过处理SimpleMembershipProvider中的一些代码来覆盖ExtendedMembershipProvider。

MVC4应用程序 - 如何删除实体框架并实现SimpleMembershipProvider?

Copied the image from - SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates

从 - SimpleMembership,Membership Providers,Universal Providers和新的ASP.NET 4.5 Web窗体和ASP.NET MVC 4模板复制图像

#2


0  

According to this post

根据这篇文章

Note that SimpleMembership still requires some flavor of SQL Server - it won't work with MySQL, NoSQL databases, etc. You can take a look at the code in WebMatrix.WebData.dll using a tool like ILSpy if you'd like to see why - there are places where SQL Server specific SQL statements are being executed, especially when creating and initializing tables. It seems like you might be able to work with another database if you created the tables separately, but I haven't tried it and it's not supported at this point.

请注意,SimpleMembership仍然需要一些SQL Server的味道 - 它不适用于MySQL,NoSQL数据库等。如果你想看看,你可以使用像ILSpy这样的工具来查看WebMatrix.WebData.dll中的代码。原因 - 有些地方正在执行SQL Server特定的SQL语句,尤其是在创建和初始化表时。如果您单独创建表,似乎您可以使用其他数据库,但我还没有尝试过,此时不支持它。

However you may see this post regarding authentication and authorization using ravendb

但是,您可能会看到有关使用ravendb进行身份验证和授权的帖子

#1


1  

SimpleMembershipProvider doesn't use Entity Framework. Instead, it has own SQL operations.

SimpleMembershipProvider不使用Entity Framework。相反,它有自己的SQL操作。

You can look at the source of SimpleMembershipProvider.cs

您可以查看SimpleMembershipProvider.cs的来源

If you want to implement a custom provider (to support both Forms and OAuth authentication), you want to override ExtendedMembershipProvider by coping some codes from SimpleMembershipProvider.

如果要实现自定义提供程序(以支持Forms和OAuth身份验证),您希望通过处理SimpleMembershipProvider中的一些代码来覆盖ExtendedMembershipProvider。

MVC4应用程序 - 如何删除实体框架并实现SimpleMembershipProvider?

Copied the image from - SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates

从 - SimpleMembership,Membership Providers,Universal Providers和新的ASP.NET 4.5 Web窗体和ASP.NET MVC 4模板复制图像

#2


0  

According to this post

根据这篇文章

Note that SimpleMembership still requires some flavor of SQL Server - it won't work with MySQL, NoSQL databases, etc. You can take a look at the code in WebMatrix.WebData.dll using a tool like ILSpy if you'd like to see why - there are places where SQL Server specific SQL statements are being executed, especially when creating and initializing tables. It seems like you might be able to work with another database if you created the tables separately, but I haven't tried it and it's not supported at this point.

请注意,SimpleMembership仍然需要一些SQL Server的味道 - 它不适用于MySQL,NoSQL数据库等。如果你想看看,你可以使用像ILSpy这样的工具来查看WebMatrix.WebData.dll中的代码。原因 - 有些地方正在执行SQL Server特定的SQL语句,尤其是在创建和初始化表时。如果您单独创建表,似乎您可以使用其他数据库,但我还没有尝试过,此时不支持它。

However you may see this post regarding authentication and authorization using ravendb

但是,您可能会看到有关使用ravendb进行身份验证和授权的帖子