EF的ASP.NET成员资格提供程序

时间:2022-09-18 08:59:26

I have been using ASP.NET membership provider the way it comes and it s been just fine serving my basic purposes. One thing I realize is that, it installs bunch of Stored Procs etc to the database.

我一直在使用ASP.NET成员资格提供程序,它一直很好地服务于我的基本目的。我意识到的一件事是,它将一堆Stored Procs等安装到数据库中。

Is there a EF implementation of ASP.NET membership ? or will there be?

是否有ASP.NET成员资格的EF实现?还是会有?

I have an up coming project which i will need to extend the functionality of the Membership providers with roles and authorization via some GUI.

我有一个即将到来的项目,我需要通过一些GUI扩展成员资格提供者的功能和角色和授权。

Moreover, everytime I use this, I have two connection string in my web.config one for DbContext one for Application services particularly for Membership provider. Why cant i have just one?

此外,每次我使用它时,我在web.config中有两个连接字符串,一个用于DbContext,一个用于Application服务,特别是对于Membership provider。为什么我不能只有一个?

3 个解决方案

#1


0  

There are gui membership management systems for MVC3 you can take a look at or add to your project.

有MVI3的gui会员管理系统,您可以查看或添加到您的项目。

You can play around with them and see how they work. It's simple once you know where to look and you can create your own.

你可以玩它们,看看它们是如何工作的。一旦你知道去哪里看就很简单,你可以创建自己的。

The Membership Class and MembershipUser Class holds all the user info. For example to un-approve a user you can do this:

Membership Class和MembershipUser Class包含所有用户信息。例如,要取消批准用户,您可以执行以下操作:

MembershipUser user = Membership.GetUser("userName");
user.IsApproved = false;
Membership.UpdateUser(user);

And if you want to delete a user, you can use Membership.DeleteUser("userName");.

如果要删除用户,可以使用Membership.DeleteUser(“userName”);.

The Roles Class has all the role associated info. Like Roles.GetUsersInRole("roleName") will return a list of all the users in the role roleName. Roles.CreateRole("roleName"); will create a role, and Roles.DeleteRole("roleName"); will delete a role.

角色类具有所有角色相关信息。与Roles.GetUsersInRole(“roleName”)一样,将返回角色roleName中所有用户的列表。 Roles.CreateRole( “ROLENAME”);将创建一个角色,和Roles.DeleteRole(“roleName”);将删除一个角色。

If you need more than just the default, you can look at Implementing a Membership Provider.

如果您需要的不仅仅是默认值,您可以查看实施成员资格提供程序。

As far as having two databases, this is not necessary. You can add all the ASP.NET tables, stored procedures, etc. to your database by using the Aspnet_regsql tool. Take a look at Installing the Database using Aspnet_regsql.exe. This will allow you to only have one database, so you can remove the asp.net connection string in your Web.Config and then change the AspNetSqlMembershipProvider AspNetSqlProfileProvider AspNetSqlRoleProvider and maybe others, to use the connection string to your main database.

至于拥有两个数据库,这不是必需的。您可以使用Aspnet_regsql工具将所有ASP.NET表,存储过程等添加到数据库中。看一下使用Aspnet_regsql.exe安装数据库。这将允许您只有一个数据库,因此您可以删除Web.Config中的asp.net连接字符串,然后更改AspNetSqlMembershipProvider AspNetSqlProfileProvider AspNetSqlRoleProvider以及其他人,以使用连接字符串到主数据库。

#2


2  

The universal providers are what you are looking for: http://nuget.org/packages/Microsoft.AspNet.Providers.Core

您正在寻找通用提供商:http://nuget.org/packages/Microsoft.AspNet.Providers.Core

These are implemented using EF Code First 5 internally, we will be making the internal DBContexts public once we make sure everything works smoothly.

这些是在内部使用EF Code First 5实现的,一旦我们确保一切顺利进行,我们将公开内部DBContexts。

#3


0  

For ASP.NET membership provider and Roles implementation in Entity Framework, need to import all views of ASPNETDB (Membership database) in EDMX file. e.g. vw_aspnet_MembershipUsers, vw_aspnet_Roles, vw_aspnet_UsersInRoles, vw_aspnet_Users, etc...

对于ASP.NET成员资格提供程序和Entity Framework中的Roles实现,需要在EDMX文件中导入ASPNETDB(成员资格数据库)的所有视图。例如vw_aspnet_MembershipUsers,vw_aspnet_Roles,vw_aspnet_UsersInRoles,vw_aspnet_Users等...

Then Membership will be run via EF. So, You can provide GUI using below functions.

然后会员资格将通过EF运行。因此,您可以使用以下功能提供GUI。

here is controller code. e.g.

这是控制器代码。例如

  // GET: /Membership/Edit/5

    public ActionResult Edit(Guid id)
    {
        var recordToEdit = (from r in _db.vw_aspnet_Users where r.UserId == id select r).First();
        return View(recordToEdit);
    }

    public ActionResult Index()
    {
        return View(_db.vw_aspnet_MembershipUsers.ToList());
    }

Now, How to merge the ASPNETDB to existing Database, to make only one connection string in web.config. (Your question: Why cant i have just one?)

现在,如何将ASPNETDB合并到现有数据库,在web.config中只创建一个连接字符串。 (你的问题:为什么我只有一个?)

That is also possible using below steps.

使用以下步骤也是可能的。

ASPNETDB.MDF is membership provider database and is used for storing and retrieving membership data from database and here we are going to see how to create membership provider database . The command used to create Aspnetdb.mdf is ASPNET_RegSQL.EXE

ASPNETDB.MDF是成员资格提供者数据库,用于存储和检索数据库中的成员资格数据,在这里我们将看到如何创建成员资格提供者数据库。用于创建Aspnetdb.mdf的命令是ASPNET_RegSQL.EXE

1.Start->Programs->Microsoft visual studio 2005->visual studio tools->Visual Studio 2005 command prompt. Type ASPNET_RegSQL.EXE in the visual Studio 2005 command prompt

1.Start-> Programs-> Microsoft visual studio 2005-> visual studio tools-> Visual Studio 2005命令提示符。在Visual Studio 2005命令提示符下键入ASPNET_RegSQL.EXE

  1. A wizard with the heading ” Welcome To The Asp.Net Sql Server Wizard ” will be displayed. Here need to click Next

    将显示标题为“欢迎使用Asp.Net Sql Server向导”的向导。这里需要单击“下一步”

  2. Next a wizard with ” Select Setup Option ” will displayed. Now we need to select setup option “Configure sql server for application purpose is default”. Select which one you wants and next.

    接下来将显示带有“选择安装选项”的向导。现在我们需要选择安装选项“为应用程序配置sql server是默认的”。选择你想要的和下一个。

  3. A window with ” Select Sql Server Database ” Will be shown Now we need to select our sql server database. Here needs to set server, authentication type and database. If select the default name”aspnetDb.mdf” will be selected. If you wants to modify existing database select that database.

    将显示一个带有“选择Sql Server数据库”的窗口现在我们需要选择我们的sql server数据库。这里需要设置服务器,身份验证类型和数据库。如果选择,将选择默认名称“aspnetDb.mdf”。如果要修改现有数据库,请选择该数据库。

5.Now A confirm will be displayed with heading “Confirm your Settings”. Now check servername and database name and click next.

5.现在将显示标题为“确认您的设置”的确认。现在检查servername和数据库名称,然后单击下一步。

  1. A window with ” The database Has Been Created Or Modified ” Will displayed. Now click Finish
  2. 将显示“已创建或修改数据库”的窗口。现在单击Finish

Be careful in above steps you need to select your existing database, Some tables (11+), views, stored procedures of Membership and Roles will be added to your existing database....

在上面的步骤中要小心,您需要选择现有的数据库,一些表(11 +),视图,成员和角色的存储过程将添加到您现有的数据库....

Enjoy it....Thank you...

享受它....谢谢......

#1


0  

There are gui membership management systems for MVC3 you can take a look at or add to your project.

有MVI3的gui会员管理系统,您可以查看或添加到您的项目。

You can play around with them and see how they work. It's simple once you know where to look and you can create your own.

你可以玩它们,看看它们是如何工作的。一旦你知道去哪里看就很简单,你可以创建自己的。

The Membership Class and MembershipUser Class holds all the user info. For example to un-approve a user you can do this:

Membership Class和MembershipUser Class包含所有用户信息。例如,要取消批准用户,您可以执行以下操作:

MembershipUser user = Membership.GetUser("userName");
user.IsApproved = false;
Membership.UpdateUser(user);

And if you want to delete a user, you can use Membership.DeleteUser("userName");.

如果要删除用户,可以使用Membership.DeleteUser(“userName”);.

The Roles Class has all the role associated info. Like Roles.GetUsersInRole("roleName") will return a list of all the users in the role roleName. Roles.CreateRole("roleName"); will create a role, and Roles.DeleteRole("roleName"); will delete a role.

角色类具有所有角色相关信息。与Roles.GetUsersInRole(“roleName”)一样,将返回角色roleName中所有用户的列表。 Roles.CreateRole( “ROLENAME”);将创建一个角色,和Roles.DeleteRole(“roleName”);将删除一个角色。

If you need more than just the default, you can look at Implementing a Membership Provider.

如果您需要的不仅仅是默认值,您可以查看实施成员资格提供程序。

As far as having two databases, this is not necessary. You can add all the ASP.NET tables, stored procedures, etc. to your database by using the Aspnet_regsql tool. Take a look at Installing the Database using Aspnet_regsql.exe. This will allow you to only have one database, so you can remove the asp.net connection string in your Web.Config and then change the AspNetSqlMembershipProvider AspNetSqlProfileProvider AspNetSqlRoleProvider and maybe others, to use the connection string to your main database.

至于拥有两个数据库,这不是必需的。您可以使用Aspnet_regsql工具将所有ASP.NET表,存储过程等添加到数据库中。看一下使用Aspnet_regsql.exe安装数据库。这将允许您只有一个数据库,因此您可以删除Web.Config中的asp.net连接字符串,然后更改AspNetSqlMembershipProvider AspNetSqlProfileProvider AspNetSqlRoleProvider以及其他人,以使用连接字符串到主数据库。

#2


2  

The universal providers are what you are looking for: http://nuget.org/packages/Microsoft.AspNet.Providers.Core

您正在寻找通用提供商:http://nuget.org/packages/Microsoft.AspNet.Providers.Core

These are implemented using EF Code First 5 internally, we will be making the internal DBContexts public once we make sure everything works smoothly.

这些是在内部使用EF Code First 5实现的,一旦我们确保一切顺利进行,我们将公开内部DBContexts。

#3


0  

For ASP.NET membership provider and Roles implementation in Entity Framework, need to import all views of ASPNETDB (Membership database) in EDMX file. e.g. vw_aspnet_MembershipUsers, vw_aspnet_Roles, vw_aspnet_UsersInRoles, vw_aspnet_Users, etc...

对于ASP.NET成员资格提供程序和Entity Framework中的Roles实现,需要在EDMX文件中导入ASPNETDB(成员资格数据库)的所有视图。例如vw_aspnet_MembershipUsers,vw_aspnet_Roles,vw_aspnet_UsersInRoles,vw_aspnet_Users等...

Then Membership will be run via EF. So, You can provide GUI using below functions.

然后会员资格将通过EF运行。因此,您可以使用以下功能提供GUI。

here is controller code. e.g.

这是控制器代码。例如

  // GET: /Membership/Edit/5

    public ActionResult Edit(Guid id)
    {
        var recordToEdit = (from r in _db.vw_aspnet_Users where r.UserId == id select r).First();
        return View(recordToEdit);
    }

    public ActionResult Index()
    {
        return View(_db.vw_aspnet_MembershipUsers.ToList());
    }

Now, How to merge the ASPNETDB to existing Database, to make only one connection string in web.config. (Your question: Why cant i have just one?)

现在,如何将ASPNETDB合并到现有数据库,在web.config中只创建一个连接字符串。 (你的问题:为什么我只有一个?)

That is also possible using below steps.

使用以下步骤也是可能的。

ASPNETDB.MDF is membership provider database and is used for storing and retrieving membership data from database and here we are going to see how to create membership provider database . The command used to create Aspnetdb.mdf is ASPNET_RegSQL.EXE

ASPNETDB.MDF是成员资格提供者数据库,用于存储和检索数据库中的成员资格数据,在这里我们将看到如何创建成员资格提供者数据库。用于创建Aspnetdb.mdf的命令是ASPNET_RegSQL.EXE

1.Start->Programs->Microsoft visual studio 2005->visual studio tools->Visual Studio 2005 command prompt. Type ASPNET_RegSQL.EXE in the visual Studio 2005 command prompt

1.Start-> Programs-> Microsoft visual studio 2005-> visual studio tools-> Visual Studio 2005命令提示符。在Visual Studio 2005命令提示符下键入ASPNET_RegSQL.EXE

  1. A wizard with the heading ” Welcome To The Asp.Net Sql Server Wizard ” will be displayed. Here need to click Next

    将显示标题为“欢迎使用Asp.Net Sql Server向导”的向导。这里需要单击“下一步”

  2. Next a wizard with ” Select Setup Option ” will displayed. Now we need to select setup option “Configure sql server for application purpose is default”. Select which one you wants and next.

    接下来将显示带有“选择安装选项”的向导。现在我们需要选择安装选项“为应用程序配置sql server是默认的”。选择你想要的和下一个。

  3. A window with ” Select Sql Server Database ” Will be shown Now we need to select our sql server database. Here needs to set server, authentication type and database. If select the default name”aspnetDb.mdf” will be selected. If you wants to modify existing database select that database.

    将显示一个带有“选择Sql Server数据库”的窗口现在我们需要选择我们的sql server数据库。这里需要设置服务器,身份验证类型和数据库。如果选择,将选择默认名称“aspnetDb.mdf”。如果要修改现有数据库,请选择该数据库。

5.Now A confirm will be displayed with heading “Confirm your Settings”. Now check servername and database name and click next.

5.现在将显示标题为“确认您的设置”的确认。现在检查servername和数据库名称,然后单击下一步。

  1. A window with ” The database Has Been Created Or Modified ” Will displayed. Now click Finish
  2. 将显示“已创建或修改数据库”的窗口。现在单击Finish

Be careful in above steps you need to select your existing database, Some tables (11+), views, stored procedures of Membership and Roles will be added to your existing database....

在上面的步骤中要小心,您需要选择现有的数据库,一些表(11 +),视图,成员和角色的存储过程将添加到您现有的数据库....

Enjoy it....Thank you...

享受它....谢谢......